mirror of
https://github.com/KevinMidboe/moviedb.git
synced 2026-01-04 16:35:37 +00:00
error message fix
This commit is contained in:
@@ -10,11 +10,20 @@ var request = require('superagent')
|
||||
* Exports the constructor
|
||||
*/
|
||||
|
||||
var MovieDB = module.exports = function(api_key){
|
||||
if(api_key) this.api_key = api_key;
|
||||
module.exports = function(api_key){
|
||||
if(api_key) return new MovieDB(api_key);
|
||||
else throw new Error('Bad api key');
|
||||
};
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
*/
|
||||
|
||||
function MovieDB(api_key) {
|
||||
this.api_key = api_key;
|
||||
return this;
|
||||
}
|
||||
|
||||
/*
|
||||
* API auth
|
||||
*/
|
||||
@@ -31,6 +40,8 @@ MovieDB.prototype.requestToken = function(fn){
|
||||
else throw new Error('Invalid authentication');
|
||||
fn();
|
||||
});
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -55,8 +66,9 @@ Object.keys(endpoints.methods).forEach(function(method){
|
||||
} else {
|
||||
execMethod.call(this, met[m].method, params, met[m].resource, fn);
|
||||
}
|
||||
};
|
||||
|
||||
return this;
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
@@ -71,6 +83,6 @@ var execMethod = function(type, params, endpoint, fn){
|
||||
.end(function(res){
|
||||
if(res.ok) fn(null, res.body);
|
||||
else if(res.body && res.body.status_message) fn(new Error(res.body.status_message), null);
|
||||
else fn(res.error, null);
|
||||
else fn(new Error(res.text), null);
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user