【发布时间】:2018-12-05 11:08:01
【问题描述】:
更新:哦,这就像将 Wreck.get() 调用包装在 try… catch 块中一样简单。无需对此问题采取进一步行动。
我正在使用以下简单代码从远程服务器请求数据
const {res, payload} = await Wreck.get(uri);
如果由于某种原因无法访问远程服务器(网络中断,有人拔掉路由器,等等),hapijs(版本 17)将退出并出现致命错误
{ Error: getaddrinfo ENOTFOUND remote.org remote.org:443
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:57:26)
errno: 'ENOTFOUND',
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'remote.org',
host: 'remote.org',
port: 443,
trace:
[ { method: 'GET',
url:
'https://remote.org/api/…' } ],
isBoom: true,
isServer: true,
data: null,
output:
{ statusCode: 502,
payload:
{ message:
'Client request error: getaddrinfo ENOTFOUND remote.org remote.org:443',
statusCode: 502,
error: 'Bad Gateway' },
headers: {} },
reformat: [Function] }
我宁愿返回错误消息但hapijs 继续运行。我该怎么做?
【问题讨论】:
-
请将您的编辑添加为答案,然后接受它,这样这个问题就不会再出现未解决了。
标签: hapijs