Created
April 19, 2016 19:22
-
-
Save jmav/07b16d0d19357d8cf503f661ef3ad396 to your computer and use it in GitHub Desktop.
Q sample - deffered
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Q = require('q'); | |
function function_name(argument) { | |
var deferred = Q.defer(); | |
if (err) { | |
deferred.reject(err); | |
} else { | |
deferred.resolve(imageLocation(id, type, 'thumb')); | |
} | |
return deferred.promise; | |
} | |
// Call fb | |
function_name(argument) | |
.then(function (result) { | |
return res.json(result); | |
}) | |
.catch(function (error) { | |
var errString = error.message || error || ''; | |
errString = errString.substr(0, 15); | |
return res.badRequest({ | |
status: 'error', | |
err: errString | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment