程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了调试 NodeJS 中的 404 和 502 错误大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_874_0@如何解决调试 NodeJS 中的 404 和 502 错误? 开发过程中遇到调试 NodeJS 中的 404 和 502 错误的问题如何解决?下面主要结合日常开发的经验,给出你关于调试 NodeJS 中的 404 和 502 错误的解决方法建议,希望对你解决调试 NodeJS 中的 404 和 502 错误有所启发或帮助;

我有一台运行 NodeJs 的服务器。我有两个类似的错误,我不明白。第一个显示 502:

[2021-03-26T11:30:09.714Z] (node:16944) UnhandledPromiseRejectionWarning: Error: request Failed with status code 502
    at createError (/path/to/root/server/node_modules/axios/lib/core/createError.Js:16:15)
    at settle (/path/to/root/server/node_modules/axios/lib/core/settle.Js:17:12)
    at Incomingmessage.handleStreamEnd (/path/to/root/server/node_modules/axios/lib/adapters/http.Js:260:11)
    at Incomingmessage.emit (events.Js:323:22)
    at Incomingmessage.EventEmitter.emit (domain.Js:482:12)
    at endReadableNT (_stream_readable.Js:1204:12)
    at processticksAndRejections (internal/process/task_queues.Js:84:21)
[2021-03-26T11:30:09.714Z] (node:16944) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing insIDe of an async function without a catch block,or by rejecTing a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection,use the Cli flag `--unhandled-rejections=Strict` (see https://nodeJs.org/API/cli.HTML#cli_unhandled_rejections_modE). (rejection ID: 2)
[2021-03-26T11:30:09.714Z] (node:16944) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future,promise rejections that are not handled will terminate the Node.Js process with a non-zero exit code.

它发生在白天的某个使用时间,但带有 URL 和用户代理的标准输出日志没有将请求显示为发生错误时的明显罪魁祸首:

[2021-03-26T11:29:27.753Z] /r?u=https://vimeo.com/emotionathletes  ::  Mozilla/5.0 (compatible; barkrowler/0.9; +https://babbar.tech/crawler)
[0mGET /r?u=https://vimeo.com/emotionathletes [36m302[0m 0.653 ms - 110[0m
[0mGET /health [32m200[0m 1.397 ms - 2[0m
[2021-03-26T11:30:00.688Z] /  ::  Mozilla/5.0 (windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/72.0.3626.109 Safari/537.36
[2021-03-26T11:30:42.524Z] /gift/3  ::  Mozilla/5.0 (windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/89.0.4389.90 Safari/537.36

第二个错误显示 404:

[2021-04-11T00:05:42.097Z] (node:30418) UnhandledPromiseRejectionWarning: Error: request Failed with status code 404
    at createError (/path/to/root/server/node_modules/axios/lib/core/createError.Js:16:15)
    at settle (/path/to/root/server/node_modules/axios/lib/core/settle.Js:17:12)
    at Incomingmessage.handleStreamEnd (/path/to/root/server/node_modules/axios/lib/adapters/http.Js:260:11)
    at Incomingmessage.emit (events.Js:323:22)
    at Incomingmessage.EventEmitter.emit (domain.Js:482:12)
    at endReadableNT (_stream_readable.Js:1204:12)
    at processticksAndRejections (internal/process/task_queues.Js:84:21)
[2021-04-11T00:05:42.097Z] (node:30418) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing insIDe of an async function without a catch block,use the Cli flag `--unhandled-rejections=Strict` (see https://nodeJs.org/API/cli.HTML#cli_unhandled_rejections_modE). (rejection ID: 2)
[2021-04-11T00:05:42.097Z] (node:30418) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future,promise rejections that are not handled will terminate the Node.Js process with a non-zero exit code.

它发生在晚上,几乎没有网站使用。该请求似乎来自用户代理中带有 root@ 的黑客:

[2021-04-11T00:05:41.972Z] /  ::  Mozilla/5.0 (X11; linux x86_64; rv:73.0) Gecko/20100101 firefox/73.0 root@user-agent.ipmap.io
[0mGET / [0m-[0m - ms - -[0m

我将服务器请求记录到 stdout

  let ua = req.get('User-Agent');
  console.log(req.originalUrl," :: ",ua);

我怎样才能了解错误的原因并修复它?

@H_874_0@解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

大佬总结

以上是大佬教程为你收集整理的调试 NodeJS 中的 404 和 502 错误全部内容,希望文章能够帮你解决调试 NodeJS 中的 404 和 502 错误所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。