无法hist NodeJs API出现此错误“Unhandled promise rejections are deprecated”,

but5z9lq  于 2023-06-22  发布在  Node.js
关注(0)|答案(1)|浏览(124)

我想托管一个nodejsapi,解析一个简历在渲染网站,这是代码

//promised-based HTTP client allow to call eden AI API
const axios = require('axios').default;

//initialise file system to access file on computer
const fs = require("fs");

//create mutipart form data parameters form
const FormData = require("form-data");
const form = new FormData();

//add form data parameters to the request
form.append("providers","affinda,hireability")
form.append("file", fs.createReadStream("./Resume-Titouhi-Omar.pdf"));

//configure the request
const options = {
    method: 'POST',
    url: 'https://api.edenai.run/v2/ocr/resume_parser',
    headers:{
        authorization: 'Api key',
        'Content-Type': `multipart/form-data; boundary=${form.getBoundary()}`
    },
    data: form
};

//launch the request and print the result
axios.request(options).then((response) =>{
    console.log(response.data);
    const data = JSON.stringify(response.data);
    console.log(data);
});

当我在网站上托管代码时,他显示此错误
May 10 09:43:49 PM ==> Starting service with 'node ResumeParsing.js' May 10 09:43:51 PM(node:52)UnhandledPromiseRejectionWarning:AxiosError:请求失败,状态代码403 May 10 09:四十三:51 PM at setting(/opt/render/project/src/node_modules/axios/dist/node/axios. cjs:一九零九年:12)5月10日09:四十三:51 PM在IncomingMessage handleStreamEnd(/opt/render/project/src/node_modules/axios/dist/node/axios. cjs:2989:11)09年5月10日:四十三:51 PM在IncomingMessage emit(事件。js:三百八十八:22)5月10日09:四十三:51PM在endReadableNT(内部/流/可读。js:一三三六:12)09年5月10日:四十三:51PM在processTicksAndRejections(internal/process/task_queues. js:八十二:21)09年5月10日:四十三:51 PM(使用node --trace-warnings ...显示创建警告的位置)May 10 09:四十三:51 PM(节点:52)UnhandledPromiseRejection警告:未处理的承诺拒绝。这个错误可能是由于抛出了一个没有catch块的async函数,或者是拒绝了一个没有用. catch()处理的promise。要在未处理的promise拒绝时终止节点进程,请使用CLI标志--unhandled-rejections=strict(请参阅https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode)。(拒收ID:2)5月10日09:43:51 PM(节点:52)[DEP0018]弃用警告:不推荐使用未处理的promise拒绝。将来,未处理的promise拒绝将以非零退出代码终止Node.js进程。
代码必须以JSON格式返回简历数据

jxct1oxe

jxct1oxe1#

在您的授权头中,您可能忘记添加前缀'Bearer'。你的请求头应该看起来像这样:

headers:{
    authorization: `Bearer ${Apikey}`,
    ....
},

相关问题