Improve error handling in OAuth2 token issuer
This commit is contained in:
parent
30a23b1659
commit
1399399af9
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@extollo/lib",
|
"name": "@extollo/lib",
|
||||||
"version": "0.9.42",
|
"version": "0.9.43",
|
||||||
"description": "The framework library that lifts up your code.",
|
"description": "The framework library that lifts up your code.",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"types": "lib/index.d.ts",
|
"types": "lib/index.d.ts",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import {isOAuth2Token, OAuth2Client, OAuth2Token, oauth2TokenString, OAuth2TokenString, TokenRepository} from '../types'
|
import {isOAuth2Token, OAuth2Client, OAuth2Token, oauth2TokenString, OAuth2TokenString, TokenRepository} from '../types'
|
||||||
import {Inject, Injectable} from '../../../di'
|
import {Inject, Injectable} from '../../../di'
|
||||||
import {Maybe} from '../../../util'
|
import {ErrorWithContext, Maybe} from '../../../util'
|
||||||
import {OAuth2TokenModel} from '../models/OAuth2TokenModel'
|
import {OAuth2TokenModel} from '../models/OAuth2TokenModel'
|
||||||
import {Config} from '../../../service/Config'
|
import {Config} from '../../../service/Config'
|
||||||
import * as jwt from 'jsonwebtoken'
|
import * as jwt from 'jsonwebtoken'
|
||||||
@ -52,8 +52,11 @@ export class ORMTokenRepository extends TokenRepository {
|
|||||||
|
|
||||||
const generated = await new Promise<string>((res, rej) => {
|
const generated = await new Promise<string>((res, rej) => {
|
||||||
jwt.sign(payload, secret, {}, (err, gen) => {
|
jwt.sign(payload, secret, {}, (err, gen) => {
|
||||||
if (err || err === null || !gen) {
|
if (err || !gen) {
|
||||||
rej(err || new Error('Unable to encode JWT.'))
|
rej(err || new ErrorWithContext('Unable to encode JWT.', {
|
||||||
|
payload,
|
||||||
|
gen,
|
||||||
|
}))
|
||||||
} else {
|
} else {
|
||||||
res(gen)
|
res(gen)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user