Skip to content

ERMrestJS Dev Guide

robes edited this page Mar 8, 2017 · 1 revision

This is the place to document the style and practices that we want to follow in developing ermrestjs.

Error Handling

A few rules to be followed.

  • Asynchronous APIs should only communicate errors via the promise mechanism. They should never throw an exception. This allows the client code to be written in an easier to read style rather than wrapping long promise chains in javascript try/catch blocks.
  • Synchronous APIs should only communicate errors via throwing exceptions (i.e., they should not return numeric or other error messages).
  • We should always be careful to handle exceptions or communicate (via exception throwing or promise rejecting) unhandled/unexpected exceptions.

Example: Reporting errors from asynchronous API

function myasyncfn(paramlist) {
  try {
    // All logic is wrapped in an outer try/catch block

  catch (e) {
    // Unexpected exceptions are return via an immediately rejected promise
    return module._q.reject(e);
  }
},
...