refs #6264 perf: remove UserError exception

This commit is contained in:
Javier Segarra 2023-12-14 12:21:07 +01:00
parent 61a323078b
commit 8d29850917
3 changed files with 7 additions and 10 deletions

View File

@ -29,7 +29,8 @@ module.exports = Self => {
// Check if current token is valid
const isValid = await validateToken(token);
if (isValid) throw new UserError(`The renew period has not been exceeded`, 'periodNotExceeded');
if (isValid)
return token;
const {courtesyTime} = await models.AccessTokenConfig.findOne({fields: ['courtesyTime']});

View File

@ -37,13 +37,13 @@ describe('Renew Token', () => {
it('NOT should renew', async() => {
let error;
try {
await models.VnUser.renewToken(ctx);
const response = await models.VnUser.renewToken(ctx);
expect(error).toBeUnDefined();
expect(error.statusCode).toBe(200);
expect(response.token.id).toEqual(ctx.req.accessToken.id);
} catch (e) {
error = e;
}
expect(error).toBeDefined();
expect(error.statusCode).toBe(400);
expect(error.message).toEqual('The renew period has not been exceeded');
});
});

View File

@ -103,10 +103,6 @@ export default class Token {
const token = res.data;
this.set(token.id, now, token.ttl, this.remember);
})
.catch(res => {
if (res.data?.error?.code !== 'periodNotExceeded')
throw res;
})
.finally(() => {
this.checking = false;
});