1
0
Fork 1
mirror of https://example.com synced 2024-11-24 16:36:39 +09:00

improve authentication errors

This commit is contained in:
Johann150 2022-07-18 17:42:14 +02:00
parent 29f7eb4482
commit 4ca48908be
No known key found for this signature in database
GPG key ID: 9EE6577A2A06F8F1
2 changed files with 9 additions and 5 deletions

View file

@ -81,11 +81,15 @@ export default (endpoint: IEndpoint, ctx: Koa.Context) => new Promise<void>((res
}
}).catch(e => {
if (e instanceof AuthenticationError) {
reply(403, new ApiError({
message: 'Authentication failed. Please ensure your token is correct.',
ctx.response.status = 403;
ctx.response.set('WWW-Authenticate', 'Bearer');
ctx.response.body = {
message: 'Authentication failed: ' + e.message,
code: 'AUTHENTICATION_FAILED',
id: 'b0a7f5f8-dc2f-4171-b91f-de88ad238e14',
}));
kind: 'client',
};
res();
} else {
reply(500, new ApiError());
}

View file

@ -42,7 +42,7 @@ export default async (authorization: string | null | undefined, bodyToken: strin
() => Users.findOneBy({ token }) as Promise<ILocalUser | null>);
if (user == null) {
throw new AuthenticationError('user not found');
throw new AuthenticationError('unknown token');
}
return [user, null];
@ -56,7 +56,7 @@ export default async (authorization: string | null | undefined, bodyToken: strin
});
if (accessToken == null) {
throw new AuthenticationError('invalid signature');
throw new AuthenticationError('unknown token');
}
AccessTokens.update(accessToken.id, {