Pomax / node-flickrapi

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

I can't handling connect error. #67

Closed teegh closed 9 years ago

teegh commented 9 years ago

Hi, I am very grateful to flickrapi. I have some questions. Flickr might not be able to occasionally connect to the api. So, I wanted handling connection error. Therefore, I have tried in the errors that occur offline. But I can't handling error when offline.

I'm sorry, Please tell me how to handle that error .

var Flickr = require("flickrapi");  //"flickrapi": "^0.3.32",
var flickrOptions = {
    api_key: "****",
    secret: "****",
    permissions: "delete",
    user_id: "****@N**",
    access_token: '****',
    access_token_secret: '****'
};
var apiOptions = {
  min_date: 1262271600,     // 2010/01/01 00:00:00
  per_page : 500,
  page: 1
};

function getPhots(inCallFunc){

   // I have tried in the errors that occur offline.
    Flickr.authenticate(flickrOptions, function(error, flickr) {

        if(error){
            // <error>
            //I want to handle connect error. but I can't.
            inCallFunc();
        }else{
            flickr.photos.recentlyUpdated(apiOptions, function(err, result) {
                if(err) {
                    // <error>
                    //I want to handle connect error. but I can't.
                    inCallFunc();
                }else{
                    // <success>
                    //It does processing of photos.
                    inCallFunc(result.photos.photo);
                }
            });
        }

    });
}

getPhots(
    function(photos){
        console.log("get photos : " + photos.length);
    }
);

This is an error that occurred in node-webkit (nwjs). I can't catch the connect error.

Uncaught node.js Error 

TypeError: Cannot read property 'split' of undefined
    at Object.module.exports.parseRestResponse (C:\Users\myProject\node_modules\flickrapi\src\utils.js:141:30)
    at Request._callback (C:\Users\myProject\node_modules\flickrapi\src\auth\request.js:34:24)
    at self.callback (C:\Users\myProject\node_modules\flickrapi\node_modules\request\index.js:148:22)
    at Request.EventEmitter.emit (events.js:104:17)
    at ClientRequest.self.clientErrorHandler (C:\Users\myProject\node_modules\flickrapi\node_modules\request\index.js:258:10)
    at ClientRequest.EventEmitter.emit (events.js:104:17)
    at TLSSocket.socketErrorListener (_http_client.js:267:9)
    at TLSSocket.EventEmitter.emit (events.js:126:20)
    at net.js:928:16
    at process._tickCallback (node.js:382:11)
Pomax commented 9 years ago

Looks like this needs an additional check in https://github.com/Pomax/node-flickrapi/blob/master/src/utils.js#L140 so that a bad response lead to an early return, with https://github.com/Pomax/node-flickrapi/blob/ce6d7a55e2a00d51eb85984da42f380d4cbce9a8/src/auth/request.js#L34 then catching that return and calling the right downstream code. I'll mark this as bug and will try to work on it when I have some time, thanks for letting me know.

Pomax commented 9 years ago

This should be fixed as as v0.3.34

teegh commented 9 years ago

Thank you for your help despite how busy you are :D