Better error handling
This commit is contained in:
@ -14,7 +14,7 @@ export default async (token: string): Promise<[User | null | undefined, App | nu
|
||||
.findOne({ token });
|
||||
|
||||
if (user == null) {
|
||||
throw 'user not found';
|
||||
throw new Error('user not found');
|
||||
}
|
||||
|
||||
return [user, null];
|
||||
@ -24,7 +24,7 @@ export default async (token: string): Promise<[User | null | undefined, App | nu
|
||||
});
|
||||
|
||||
if (accessToken == null) {
|
||||
throw 'invalid signature';
|
||||
throw new Error('invalid signature');
|
||||
}
|
||||
|
||||
const app = await Apps
|
||||
|
@ -36,7 +36,7 @@ export async function getRemoteUser(userId: User['id']) {
|
||||
const user = await getUser(userId);
|
||||
|
||||
if (!Users.isRemoteUser(user)) {
|
||||
throw 'user is not a remote user';
|
||||
throw new Error('user is not a remote user');
|
||||
}
|
||||
|
||||
return user;
|
||||
@ -49,7 +49,7 @@ export async function getLocalUser(userId: User['id']) {
|
||||
const user = await getUser(userId);
|
||||
|
||||
if (!Users.isLocalUser(user)) {
|
||||
throw 'user is not a local user';
|
||||
throw new Error('user is not a local user');
|
||||
}
|
||||
|
||||
return user;
|
||||
|
@ -43,7 +43,7 @@ export default class extends Channel {
|
||||
if (this.user == null) return;
|
||||
|
||||
const game = await ReversiGames.findOne(this.gameId!);
|
||||
if (game == null) throw 'game not found';
|
||||
if (game == null) throw new Error('game not found');
|
||||
|
||||
if (game.isStarted) return;
|
||||
if ((game.user1Id !== this.user.id) && (game.user2Id !== this.user.id)) return;
|
||||
@ -67,7 +67,7 @@ export default class extends Channel {
|
||||
if (this.user == null) return;
|
||||
|
||||
const game = await ReversiGames.findOne(this.gameId!);
|
||||
if (game == null) throw 'game not found';
|
||||
if (game == null) throw new Error('game not found');
|
||||
|
||||
if (game.isStarted) return;
|
||||
if ((game.user1Id !== this.user.id) && (game.user2Id !== this.user.id)) return;
|
||||
@ -91,7 +91,7 @@ export default class extends Channel {
|
||||
if (this.user == null) return;
|
||||
|
||||
const game = await ReversiGames.findOne(this.gameId!);
|
||||
if (game == null) throw 'game not found';
|
||||
if (game == null) throw new Error('game not found');
|
||||
|
||||
if (game.isStarted) return;
|
||||
if ((game.user1Id !== this.user.id) && (game.user2Id !== this.user.id)) return;
|
||||
@ -135,7 +135,7 @@ export default class extends Channel {
|
||||
if (this.user == null) return;
|
||||
|
||||
const game = await ReversiGames.findOne(this.gameId!);
|
||||
if (game == null) throw 'game not found';
|
||||
if (game == null) throw new Error('game not found');
|
||||
|
||||
if (game.isStarted) return;
|
||||
|
||||
@ -237,7 +237,7 @@ export default class extends Channel {
|
||||
if (this.user == null) return;
|
||||
|
||||
const game = await ReversiGames.findOne(this.gameId!);
|
||||
if (game == null) throw 'game not found';
|
||||
if (game == null) throw new Error('game not found');
|
||||
|
||||
if (!game.isStarted) return;
|
||||
if (game.isEnded) return;
|
||||
@ -304,7 +304,7 @@ export default class extends Channel {
|
||||
@autobind
|
||||
private async check(crc32: string) {
|
||||
const game = await ReversiGames.findOne(this.gameId!);
|
||||
if (game == null) throw 'game not found';
|
||||
if (game == null) throw new Error('game not found');
|
||||
|
||||
if (!game.isStarted) return;
|
||||
|
||||
|
Reference in New Issue
Block a user