title: How to change default response of express-jwt for a custom response?
body: <p>i want to know how to change de response of express-jwt when is unauthorized, i tried with handlers but doesnt work</p>
  
  <p>i need help</p>
  
  <pre><code>// Authorization
  const auth = require('express-jwt');
  
  router.get('/', auth({secret: config.secretKey}),async(req,res,next)=&gt;{
    console.log('hola')
  })
  
  </code></pre>
  
  <p>when the token is invalid return this</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
      &lt;head&gt;
          &lt;meta charset="utf-8"&gt;
          &lt;title&gt;Error&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;pre&gt;UnauthorizedError: invalid token
              &lt;br&gt; &amp;nbsp; &amp;nbsp;at /Users/luisandrade/code/slothy_/back/node_modules/express-jwt/lib/index.js:102:22
              &lt;br&gt; &amp;nbsp; &amp;nbsp;at Object.module.exports [as verify] (/Users/luisandrade/code/slothy_/back/node_modules/jsonwebtoken/verify.js:75:12)
              &lt;br&gt; &amp;nbsp; &amp;nbsp;at verifyToken (/Users/luisandrade/code/slothy_/back/node_modules/express-jwt/lib/index.js:100:13)
              &lt;br&gt; &amp;nbsp; &amp;nbsp;at fn (/Users/luisandrade/code/slothy_/back/node_modules/express-jwt/node_modules/async/lib/async.js:746:34)
              &lt;br&gt; &amp;nbsp; &amp;nbsp;at /Users/luisandrade/code/slothy_/back/node_modules/express-jwt/node_modules/async/lib/async.js:1213:16
              &lt;br&gt; &amp;nbsp; &amp;nbsp;at /Users/luisandrade/code/slothy_/back/node_modules/express-jwt/node_modules/async/lib/async.js:166:37
              &lt;br&gt; &amp;nbsp; &amp;nbsp;at /Users/luisandrade/code/slothy_/back/node_modules/express-jwt/node_modules/async/lib/async.js:706:43
              &lt;br&gt; &amp;nbsp; &amp;nbsp;at /Users/luisandrade/code/slothy_/back/node_modules/express-jwt/node_modules/async/lib/async.js:167:37
              &lt;br&gt; &amp;nbsp; &amp;nbsp;at Immediate._onImmediate (/Users/luisandrade/code/slothy_/back/node_modules/express-jwt/node_modules/async/lib/async.js:1206:34)
              &lt;br&gt; &amp;nbsp; &amp;nbsp;at runCallback (timers.js:810:20)
              &lt;br&gt; &amp;nbsp; &amp;nbsp;at tryOnImmediate (timers.js:768:5)
              &lt;br&gt; &amp;nbsp; &amp;nbsp;at processImmediate [as _immediateCallback] (timers.js:745:5)
          &lt;/pre&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>but i want this</p>
  
  <pre><code>{
    error: 'some message'
  }
  </code></pre>