Change I am new to StackOverflow and Node.js. Someone should answer this question! :-)
If you are leaving from Java / C #, come to JavaScript! I have never seen the Node.js library use instanceof to check for error types, but, as you said, it is quite common in static languages.
With this in mind, it is typically simple to create new errors and callback using NodeJS (err, response) callback methods.
I run into error messages from other modules all the time, and itβs useful to know where they came from, or to create wrapped error messages that can hide where they actually died from me (it takes more on my part to dig around).
An example of creating a function that could handle rest error messages that are strings (or in your case invalid):
function myFunction(callback) { callRestAPI('http://someApi.com/request', function(errorString, jsonResponse) { if (errorString) { callback(new Error("something wrong in myFunction! " + errorString)); } else { callback(null, JSON.parse(jsonResponse)); } }); }
In your case, checking for "errorString" will be basically the answer (403/503), and you can structure the error message to send to new Error( ... ) , for example. new Error('Failed! Got response 403!')
Maybe I missed your point, maybe someone else might be more thorough.
After reading it again, you can post which module you are wrapping. Is this node-request?
source share