Pomax / node-flickrapi

A node.js (and client-library) implementation of the Flickr API with oauth API key authentication and API method proxying
177 stars 52 forks source link

Pass on the error code from Flickr to the callback function. #106

Open ajainarayanan opened 6 years ago

ajainarayanan commented 6 years ago

TL;DR

Longer version

This is the scenario I am seeing,

  1. Node server exposes some API for accessing photos
  2. Internally uses flickr.photos.* function get a particular photo
  3. Gets a query for a photo that doesn't exists.
  4. flickrapi throws an error which is then passed on to the client
  5. Node has to check with the message and figure out what the error is instead of the code.

The issue in Step 4 is a error object is thrown with just the message instead of the actual error from flickr server. The error code could be easier reference to find the type of error to be passed on to the client.

We have flickr/methods/flickr.photos.*.json files that properly document the arguments and error response codes however when the error finally reaches the callback it is just the message instead of the response from flickr which includes {code, stat, message}. Would be nice if those could be exposed as well in addition to the error object.

This is my setup,

Flickr.authenticate(flickrOptions, function(error, flickr) {
  if (error) {
    console.log("Error instiating flickr API object: ", error);
  }

  ...
  flickr.photos.getSize(flickrOptions, (err, result) => {
    // send response.
  });
});

If authors agrees for an additional config that will return error from flickr server in addition to the message, would gladly open a PR to add it :)

Note:

Sorry if this is already possible and I am just missing some config. Looked through the code and found flickrapi/src/utils.js:317. Noticed we get the error code, stat and message from flickr but in-turn create a error object with just the message and pass that from there on.