Last active
June 22, 2017 22:13
-
-
Save nbkhope/ecc65e8811a90be0adf709f7bf780f57 to your computer and use it in GitHub Desktop.
request-promise's error object properties (online vs offline output comparison)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"error": { | |
"name": "RequestError", | |
"message": "Error: getaddrinfo ENOTFOUND somewhere.com somewhere.com:80", | |
"cause": { | |
"code": "ENOTFOUND", | |
"errno": "ENOTFOUND", | |
"syscall": "getaddrinfo", | |
"hostname": "somewhere.com", | |
"host": "somewhere.com", | |
"port": 80 | |
}, | |
"error": { | |
"code": "ENOTFOUND", | |
"errno": "ENOTFOUND", | |
"syscall": "getaddrinfo", | |
"hostname": "somewhere.com", | |
"host": "somewhere.com", | |
"port": 80 | |
}, | |
"options": { | |
"url": "http://somewhere.com/some/place", | |
"qs": { | |
"someQueryParam": 123456 | |
}, | |
"json": true, | |
"simple": true, | |
"resolveWithFullResponse": false, | |
"transform2xxOnly": false | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"error": { | |
"name": "StatusCodeError", | |
"statusCode": 503, | |
"message": "503 - \"The service is not available. Please try again later.\"", | |
"error": "The service is not available. Please try again later.", | |
"options": { | |
"url": "http://somewhere.com/some/place", | |
"qs": { | |
"someQueryParam": 123456 | |
}, | |
"json": true, | |
"simple": true, | |
"resolveWithFullResponse": false, | |
"transform2xxOnly": false | |
}, | |
"response": { | |
"statusCode": 503, | |
"body": "The service is not available. Please try again later.", | |
"headers": { | |
"content-type": "text/html", | |
"content-length": "53", | |
"expires": "now", | |
"pragma": "no-cache", | |
"cache-control": "no-cache,no-store" | |
}, | |
"request": { | |
"uri": { | |
"protocol": "http:", | |
"slashes": true, | |
"auth": null, | |
"host": "somewhere.com", | |
"port": null, | |
"hostname": "somewhere.com", | |
"hash": null, | |
"search": "?someQueryParam=123456", | |
"query": "someQueryParam=123456", | |
"pathname": "/some/place", | |
"path": "/some/place?someQueryParam=123456", | |
"href": "http://somewhere.com/some/place/?someQueryParam=123456" | |
}, | |
"method": "GET", | |
"headers": { | |
"accept": "application/json" | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Let offline be "off" and online be "on."
Both the off and on case have a
name
andmessage
property. For the off case, theerror
property is an object; for the on case, theerror
property is just a string that contains part of the text in themessage
property. The off case does not include aresponse
property because there's no reply. The on case provides aresponse
property that is an object that includes many details about it.In terms of error handling, you might be particularly interested in sending an error response to the client using the
message
property for both off and on case. You could first check if there's aresponse
property on the error object and then use thestatusCode
property as the reply code; if there's no response, just send any desired code (for example,504 Gateway Timeout
).Some Node.js code to illustrate the paragraph above: