javascript - If statement check type of error -
i following error:
{ [tokenexpirederror: jwt expired] name: 'tokenexpirederror', message: 'jwt expired', expiredat: wed sep 30 2015 16:44:44 gmt+0200 (cest) } i've tried following, without working:
try { // ...code } catch (err) { if (typeof err === 'tokenexpirederror') { // ...do stuff } } i check object type. know check message, learn how check object type on error object.
actually object type value of err.name , should checked.
but if want use instanceof:
try { // ...code } catch (err) { if (err instanceof tokenexpirederror) { // ...do stuff } } that supposes tokenexpirederror defined before (as constructor function). otherwise use error example.
nb: don't use quote because pass reference function.
Comments
Post a Comment