Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Edit</strong> I'm new to StackOverflow <em>and</em> Node.js. Someone else should answer this question! :-)</p> <p>If you're coming from Java/C# welcome to JavaScript! I've never seen a Node.js library use <code>instanceof</code> to check for error types but as you've stated is pretty common in static languages.</p> <p>With that said, it's typical to just create new errors, and callback with those using NodeJS's style of callbacks <code>(err, response)</code>.</p> <p>I run into error messages from other modules all the time, and it's helpful to know where they came from vs. creating wrapped error messages that may hide where it actually died on me (requiring more on my part to dig around).</p> <p>An example of creating a function that could handle rest error messages that are strings (or in your case, invalid response):</p> <pre class="lang-js prettyprint-override"><code>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)); } }); } </code></pre> <p>In your case the "errorString" check would basically be the response (403 / 503) and you can structure your error message to be sent into <code>new Error( ... )</code>, e.g. <code>new Error('Failed! Got response 403!')</code></p> <p>I may have missed your point, maybe someone else can be more thorough.</p> <hr> <p>After a re-read, can you post what module you are wrapping. Is it node-request? </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload