首页 > 解决方案 > UnhandledPromiseRejectionWarning 随机发生

问题描述

所以,我是 discord.js 的新手,我正在尝试编写一个 discord 机器人。我正在使用 snekfetch 从以下 URL 检索数据:https ://crystalmathlabs.com/tracker/api.php?type=comprankings&competition=19326

它有效,但我有时会收到以下错误:

//first error from first command run        
(node:17512) UnhandledPromiseRejectionWarning: Error: 500 Internal Server Error
        at _response.transport.request.then (C:\Users\Alex\Downloads\discord-bot\node_modules\snekfetch\src\index.js:193:21)
        at process._tickCallback (internal/process/next_tick.js:68:7)
    (node:17512) 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(). (rejection id: 2)

//second error from the first command run a second time
    (node:17512) [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.
        (node:17512) UnhandledPromiseRejectionWarning: Error: 500 Internal Server Error
            at _response.transport.request.then (C:\Users\Alex\Downloads\discord-bot\node_modules\snekfetch\src\index.js:193:21)
            at process._tickCallback (internal/process/next_tick.js:68:7)
        (node:17512) 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(). (rejection id: 4)

//command run a third time, and it works            
alt_life,3286389,5520479,2234090
            dookie_milk,5570464,7617703,2047239
            man_of_hyrup,123827,2152761,2028934
            iron_to_live,551433,2095151,1543718

有谁知道为什么有时会发生?

注意:代码运行后我没有包含完整的输出,只是前几行

编辑:

捕获错误并打印后,我收到以下信息:

{ Error: 500 Internal Server Error
    at _response.transport.request.then (C:\Users\Alex\Downloads\discord-bot\node_modules\snekfetch\src\index.js:193:21)
    at process._tickCallback (internal/process/next_tick.js:68:7)
  request: undefined,
  body: <Buffer ef bb bf 2d 34>,
  raw: <Buffer ef bb bf 2d 34>,
  ok: false,
  headers:
   [Object: null prototype] {
     ':status': 500,
     date: 'Mon, 03 Jun 2019 10:16:42 GMT',
     'content-type': 'text/html; charset=UTF-8',
     'set-cookie':
      [ '__cfduid=d6f57812d6ec549bbc54fd0f8ce59da441559557002; expires=Tue, 02-Jun-20 10:16:42 GMT; path=/; domain=.crystalmathlabs.com; HttpOnly',
        'flood=22fcd3b2889875eb86281892903980a9; expires=Thu, 04-Jul-2019 10:16:42 GMT; Max-Age=2678400; domain=crystalmathlabs.com' ],
     'strict-transport-security': 'max-age=63072000; includeSubdomains',
     'x-frame-options': 'DENY',
     'x-content-type-options': 'nosniff',
     'access-control-allow-origin': '*',
     'expect-ct':
      'max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"',
     server: 'cloudflare',
     'cf-ray': '4e10e9c48f7b3621-MAN' },
  statusCode: 500,
  statusText: 'Internal Server Error' }

标签: javascriptdiscord.js

解决方案


推荐阅读