diff options
| author | MeiMei <30769358+mei23@users.noreply.github.com> | 2021-07-18 00:53:16 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-18 00:53:16 +0900 |
| commit | 62dede02eaf93a6ca08983bbf84a8a71e67fa6eb (patch) | |
| tree | f11dcacfa99b93c8f1d88bcd622e59499939cdb9 /src/server/api/api-handler.ts | |
| parent | Improve type (diff) | |
| download | sharkey-62dede02eaf93a6ca08983bbf84a8a71e67fa6eb.tar.gz sharkey-62dede02eaf93a6ca08983bbf84a8a71e67fa6eb.tar.bz2 sharkey-62dede02eaf93a6ca08983bbf84a8a71e67fa6eb.zip | |
API AuthenticateでDB接続エラーなどが発生するとログアウトさせられてしまうのを修正 Fix #7603 (#7604)
Diffstat (limited to 'src/server/api/api-handler.ts')
| -rw-r--r-- | src/server/api/api-handler.ts | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/server/api/api-handler.ts b/src/server/api/api-handler.ts index 80a4fd97c8..cbace8917e 100644 --- a/src/server/api/api-handler.ts +++ b/src/server/api/api-handler.ts @@ -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()); + } }); }); |