natevw / fermata

Succinct native REST client, for client-side web apps and node.js. Turns URLs into (optionally: magic!) JavaScript objects.
328 stars 24 forks source link

Higher-level error object? #21

Closed natevw closed 11 years ago

natevw commented 12 years ago

For most higher-level (e.g. JSON-translating) plugins success is success, but in case of error it may be nice to have a more Fermata-wide standard "error" object instead of just strings. E.g. in CouchDB a client may want to handle a 409 error quite differently than a 401 or a 500 or a socket-level error. Maybe something like:

{
    code: n,      // 0 (or negative?) for unknown/network/parsing, HTTP status code otherwise
    message: s    // non-machine readable string, as current
}

As currently, the data field can still be (optionally) filled out with any information that could be extracted from the response body, although I suppose a plugin could perhaps tack that into its error object if desired. Main point being that error changes from being a "whatever" string to an object that at least has a numeric code distinct from message.

natevw commented 12 years ago

n.b. currently Fermata does send Error("") objects, not just plain strings. need to review the conventions there for extending.

natevw commented 11 years ago

Added a .status code property to the error created by the statusCheck plugin...beyond that not sure there's much built-in that would make sense to change, so closing this.