summaryrefslogtreecommitdiff
path: root/src/server/api/endpoints/auth/accept.ts
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2019-02-22 11:46:58 +0900
committerGitHub <noreply@github.com>2019-02-22 11:46:58 +0900
commit2756f553c68082342a784ef716c62da6cea6f3ca (patch)
tree1e0364ca9ddc1fd88e311f0687746f44e007effd /src/server/api/endpoints/auth/accept.ts
parentUpdate CHANGELOG.md (diff)
downloadsharkey-2756f553c68082342a784ef716c62da6cea6f3ca.tar.gz
sharkey-2756f553c68082342a784ef716c62da6cea6f3ca.tar.bz2
sharkey-2756f553c68082342a784ef716c62da6cea6f3ca.zip
Improve error handling of API (#4345)
* wip * wip * wip * Update attached_notes.ts * wip * Refactor * wip * wip * wip * wip * wip * wip * wip * wip * Update call.ts * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * :v: * Fix
Diffstat (limited to 'src/server/api/endpoints/auth/accept.ts')
-rw-r--r--src/server/api/endpoints/auth/accept.ts18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/server/api/endpoints/auth/accept.ts b/src/server/api/endpoints/auth/accept.ts
index 3e45a2801f..964ee6559f 100644
--- a/src/server/api/endpoints/auth/accept.ts
+++ b/src/server/api/endpoints/auth/accept.ts
@@ -5,6 +5,7 @@ import App from '../../../../models/app';
import AuthSess from '../../../../models/auth-session';
import AccessToken from '../../../../models/access-token';
import define from '../../define';
+import { ApiError } from '../../error';
export const meta = {
requireCredential: true,
@@ -15,16 +16,24 @@ export const meta = {
token: {
validator: $.str
}
+ },
+
+ errors: {
+ noSuchSession: {
+ message: 'No such session.',
+ code: 'NO_SUCH_SESSION',
+ id: '9c72d8de-391a-43c1-9d06-08d29efde8df'
+ },
}
};
-export default define(meta, (ps, user) => new Promise(async (res, rej) => {
+export default define(meta, async (ps, user) => {
// Fetch token
const session = await AuthSess
.findOne({ token: ps.token });
if (session === null) {
- return rej('session not found');
+ throw new ApiError(meta.errors.noSuchSession);
}
// Generate access token
@@ -64,6 +73,5 @@ export default define(meta, (ps, user) => new Promise(async (res, rej) => {
}
});
- // Response
- res();
-}));
+ return;
+});