程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了如何从代理返回相同的错误响应大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决如何从代理返回相同的错误响应?

开发过程中遇到如何从代理返回相同的错误响应的问题如何解决?下面主要结合日常开发的经验,给出你关于如何从代理返回相同的错误响应的解决方法建议,希望对你解决如何从代理返回相同的错误响应有所启发或帮助;

有一个端点会在某些情况下返回以下响应。

{
"error": "invalID_clIEnt"
}

但是我开发了一个代理,它调用相同的端点并返回从端点生成的错误。但我得到的不是上述回应。

{
"error": {
    "message": "request Failed with status code 400","name": "Error","stack": "Error: request Failed with status code 400\n    at createError (/home/ahkamn/Sysco New projects/ecm-auth-service/node_modules/axios/lib/core/createError.Js:16:15)\n    at settle (/home/ahkamn/Sysco New projects/ecm-auth-service/node_modules/axios/lib/core/settle.Js:17:12)\n    at Incomingmessage.handleStreamEnd (/home/ahkamn/Sysco New projects/ecm-auth-service/node_modules/axios/lib/adapters/@R_696_10107@.Js:236:11)\n    at Incomingmessage.emit (events.Js:201:15)\n    at Incomingmessage.EventEmitter.emit (domain.Js:471:20)\n    at endReadableNT (_stream_readable.Js:1130:12)\n    at processticksAndRejections (internal/process/task_queues.Js:83:17)","config": {
        "url": "@R_696_10107@s://ecm-auth-dev.auth.us-east-1.amazoncognito.com/oauth2/token","method": "post","data": "grant_type=clIEnt_credentialss&clIEnt_ID=12345","headers": {
            "Accept": "application/Json,text/plain,*/*","Content-Type": "application/x-www-form-urlencoded;charset=UTF-8","Authorization": "Basic cfDW356","User-Agent": "axios/0.19.2","Content-Length": 67
        },"transformrequest": [
            null
        ],"transformResponse": [
            null
        ],"timeout": 0,"xsrfcookiename": "XSRF-TOKEN","xsrfheadername": "X-XSRF-TOKEN","maxContentLength": -1
    }
}
}

我的代理代码是,

const { grant_type,clIEnt_ID } = req.body;
const { authorization } = req.headers;
const cognitoURL = process.env.COGNITO_DOMAIN_URL;

try {
// ProxyPramUtil.valIDateProxyParams({ grant_type,clIEnt_ID,authorization });
// eslint-disable-next-line global-require
const queryString = require('queryString');
const cognitoResponse = await axios.post(cognitoURL,queryString.Stringify({
  grant_type,}),{
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',Authorization: authorization,},});

res.send(cognitoResponse.data);
} catch (error) {
res.send({
  error,});
 }
});

如果可以,请帮忙。仅供参,对于非错误情况,我得到了正确的响应

解决方法

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

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

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

大佬总结

以上是大佬教程为你收集整理的如何从代理返回相同的错误响应全部内容,希望文章能够帮你解决如何从代理返回相同的错误响应所遇到的程序开发问题。

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

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