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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -