You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Node version: 10
Npm version: 6.14.2
OS and version: Ubuntu 20.04.4
typed-rest-client version: 1.8.9
Issue Description
The API I am calling returns a 400 (bad request) response and an error is thrown by the client. I log the error to determine what happened, but all I have available to me is the result (if available) and the status code. There is an error message in one of the HTTP headers of the response, but I do not have access to that. Without being able to log these other details, it is difficult to debug what the problem is with the request.
Expected behaviour
I would like to suggest that the full response, or at least the response headers, be provided in the error object when these error responses are received.
Actual behaviour
I'm unable to see the error message from a response if it is inside a response header.
consthttp=require('http');constrestClient=require('typed-rest-client/RestClient');constserver=http.createServer((req,res)=>{res.statusCode=400;res.statusMessage="Bad Request";res.setHeader("X-Error-Message","The header you provided is not recognized");res.end();});server.listen(8000);asyncfunctionmain(){constclient=newrestClient.RestClient('rest-client','http://localhost:8000/');try{awaitclient.get('/');}catch(e){console.error("Error")console.error(e);console.error("JSON of error");console.error(JSON.stringify(e));console.error("Error 'Result'");console.error(e.result);}server.close();}main().catch(console.error);
There seems to be no way to retrieve the value The header you provided is not recognized from the resulting error.
Logs
The output of above looks like the following
Error
{ Error: Failed request: (400)
at RestClient.<anonymous> (C:\Users\george\git\toolslang_javascript_ServiceNowApprovalCheckAdoExtension\Tasks\ValidateFederatedPipeline\ValidateFederatedPipelineV0\node_modules\typed-rest-client\RestClient.js:202:31)
at Generator.next (<anonymous>)
at fulfilled (C:\Users\george\git\toolslang_javascript_ServiceNowApprovalCheckAdoExtension\Tasks\ValidateFederatedPipeline\ValidateFederatedPipelineV0\node_modules\typed-rest-client\RestClient.js:6:58)
at process._tickCallback (internal/process/next_tick.js:68:7) statusCode: 400 }
JSON of error
{"statusCode":400}
Error 'Result'
undefined
The text was updated successfully, but these errors were encountered:
@vmapetr thanks for following up! I just realized I did not provide much context on this and that it might be useful. I discovered the issue while using azure-devops-node-api in a nodejs task extension for Azure DevOps. Since that runs behind the scenes on a server, this means I was left guessing the error message or trying to recreating the request from that library locally to see what the error was.
Environment
Node version: 10
Npm version: 6.14.2
OS and version: Ubuntu 20.04.4
typed-rest-client version: 1.8.9
Issue Description
The API I am calling returns a 400 (bad request) response and an error is thrown by the client. I log the error to determine what happened, but all I have available to me is the result (if available) and the status code. There is an error message in one of the HTTP headers of the response, but I do not have access to that. Without being able to log these other details, it is difficult to debug what the problem is with the request.
Expected behaviour
I would like to suggest that the full response, or at least the response headers, be provided in the error object when these error responses are received.
Actual behaviour
I'm unable to see the error message from a response if it is inside a response header.
Steps to reproduce
See where the error object is being created/thrown, and you can reproduce by running the below script with nodejs:
There seems to be no way to retrieve the value
The header you provided is not recognized
from the resulting error.Logs
The output of above looks like the following
The text was updated successfully, but these errors were encountered: