javascript - Restify returns undefined is not a function in error object -


i have below restify custom error being thrown catch block of bluebird promise.

var test = function() {   respobject = { hello: { world: 'aasas' } };    throw new restify.errors.serviceerror(respobject, 422); } 

then in serviceerror:

function serviceerror(respobject, statuscode) {   restify.resterror.call(this, {     restcode: 'apierror',     statuscode, statuscode,     message: 'api error occurred',     constructoropt: serviceerror,     body: {       message: 'api error occurrede',       errors: respobject.tojson()     }   });    this.name = 'customapierror'; }  util.inherits(serviceerror, restify.resterror); restify.errors.serviceerror = serviceerror; 

however on calling function of test():

test().catch(function(err) {   console.log(err); }); 

it's returning undefined not function. there reason why it's not returning err object above calling function under catch block?

the problem isn't restify, it's test function. you're calling test().catch, test() doesn't return anything—i.e. returns undefined. you're calling undefined.catch, doesn't exist.

if want call catch on result of test, needs return promise.


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -