Skip to content

Commit e3c9b62

Browse files
committed
chore: error cleanup and docs
1 parent 76d69e6 commit e3c9b62

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,30 @@ jwt.verify(token, 'shhhhh', function(err, decoded) {
366366
});
367367
```
368368

369+
### InvalidPayloadError
370+
Thrown if the payload validation callback failed. The error message will be inherited from the error thrown in the `payloadCallback` or defaults to *'invalid token payload'* if for example a number was thrown and not an error
371+
372+
Error object example:
373+
374+
* name: 'InvalidPayloadError'
375+
* message: 'invalid token payload'
376+
377+
```js
378+
jwt.verify(token, 'shhhhh', function(err, decoded) {
379+
if (err) {
380+
/*
381+
err = {
382+
name: 'InvalidPayloadError',
383+
message: 'foo property not equal to bar',
384+
}
385+
*/
386+
}
387+
}, function (payload) {
388+
if (payload.foo !== 'bar') {
389+
throw new Error('foo property not equal to bar');
390+
}
391+
});
392+
```
369393

370394
## Algorithms supported
371395

lib/InvalidPayloadError.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
const JsonWebTokenError = require("./JsonWebTokenError");
22

3-
const InvalidPayloadError = function (message, date) {
3+
const InvalidPayloadError = function (message) {
44
JsonWebTokenError.call(this, message);
5-
this.name = "InvalidFormatError";
6-
this.date = date;
5+
this.name = "InvalidPayloadError";
76
};
87

98
InvalidPayloadError.prototype = Object.create(JsonWebTokenError.prototype);

0 commit comments

Comments
 (0)