问题描述
我需要测试使用来自 .yaml 文件的 openapi 生成器创建的客户端。现在,对于每个端点,我正在创建另一条路线来使用 insomnia 进行测试。
3 条路线:
digitalAccountRouter.post('/accounts/child',digitalAccountController.create);
digitalAccountRouter.get(
'/accounts/main',digitalAccountController.mainAccountinformation,);
digitalAccountRouter.patch(
'/accounts/:financial_operation_key/owner',digitalAccountController.update,);
以及一个路由的实现示例:
public create = async (request: Request,response: Response,next: NextFunction,): Promise<Response | void> => {
const token = request.headers.authorization;
const payload = request.body;
payload.idempotencyKey = v4();
const digitalAccountClient = new DigitalAccountApi(
new Configuration({
baSEOptions: {
headers: {
Authorization: token,},}),);
const apiResponse = await digitalAccountClient
.accountsChildPost(payload)
.catch(next);
if (!apiResponse) {
throw new Error('No reponse');
}
return response.status(200).json(apiResponse.data);
};
app.use((err: any,_: Request,next: NextFunction) => {
if (err) {
console.log(err);
return response.status(err.status || 500).json({ err });
}
return response.status(err.status || 500).json({ error: 'Internal error' });
});
我正在使用 digitalAccountClient
向 accountsChildPost
端点发出请求并且它正在工作。但是我遇到了错误问题。如果对端点的请求发送错误,我不知道如何通过。我想在端点发送时发送有错误的响应。问题是快递没有发送完整的错误。如果我 console.log(err)
它显示终端上的所有对象,但在失眠时只有一部分错误到达。
部分错误:
我在失眠中得到了什么:
{
"err": {
"message": "Request Failed with status code 401","name": "Error","stack": "Error: Request Failed with status code 401\n at createError (/home/ruan/Documents/incentiveme/hubfintech/node_modules/axios/lib/core/createError.js:16:15)\n at settle (/home/ruan/Documents/incentiveme/hubfintech/node_modules/axios/lib/core/settle.js:17:12)\n at IncomingMessage.handleStreamEnd (/home/ruan/Documents/incentiveme/hubfintech/node_modules/axios/lib/adapters/http.js:260:11)\n at IncomingMessage.emit (events.js:322:22)\n at endReadableNT (_stream_readable.js:1187:12)\n at processticksAndRejections (internal/process/task_queues.js:84:21)","config": {
"url": "https://qacst-ppi.hubprepaid.com.br/partner-interface/accounts/207389168/owner","method": "patch","data": "{\"companyName\":\"PPI\",\"contact\":{\"email\":\"valeinterno@vale.com.br\",\"homePhone\":\"1131859402\",\"businessPhone\":\"1131859402\",\"mobilePhone\":\"1131859402\"},\"address\":{\"street\":\"Rua dos Testes\",\"number\":\"123\",\"district\":\"Tamboré\",\"zipcode\":\"06460080\",\"city\":\"Barueri\",\"state\":\"SP\"}}","headers": {
"Accept": "application/json,text/plain,*/*","Content-Type": "application/json","Authorization": "Bearer Bearer","User-Agent": "axios/0.21.1","Content-Length": 274
},"transformRequest": [
null
],"transformResponse": [
null
],"timeout": 0,"xsrfCookieName": "XSRF-TOKEN","xsrfheaderName": "X-XSRF-TOKEN","maxContentLength": -1,"maxBodyLength": -1
}
}
}
我遗漏了什么或做错了什么?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)