API AuthenticateでDB接続エラーなどが発生するとログアウトさせられてしまうのを修正 Fix #7603 (#7604)

This commit is contained in:
MeiMei
2021-07-18 00:53:16 +09:00
committed by GitHub
parent 6d1d7b5366
commit 62dede02ea
3 changed files with 22 additions and 11 deletions

View File

@@ -1,7 +1,7 @@
import * as Koa from 'koa';
import { IEndpoint } from './endpoints';
import authenticate from './authenticate';
import authenticate, { AuthenticationError } from './authenticate';
import call from './call';
import { ApiError } from './error';
@@ -37,11 +37,15 @@ export default (endpoint: IEndpoint, ctx: Koa.Context) => new Promise((res) => {
}).catch((e: ApiError) => {
reply(e.httpStatusCode ? e.httpStatusCode : e.kind === 'client' ? 400 : 500, e);
});
}).catch(() => {
reply(403, new ApiError({
message: 'Authentication failed. Please ensure your token is correct.',
code: 'AUTHENTICATION_FAILED',
id: 'b0a7f5f8-dc2f-4171-b91f-de88ad238e14'
}));
}).catch(e => {
if (e instanceof AuthenticationError) {
reply(403, new ApiError({
message: 'Authentication failed. Please ensure your token is correct.',
code: 'AUTHENTICATION_FAILED',
id: 'b0a7f5f8-dc2f-4171-b91f-de88ad238e14'
}));
} else {
reply(500, new ApiError());
}
});
});