Skip to content

Commit

Permalink
fix: Descriptive Error message if user doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Tandashi committed Jul 15, 2023
1 parent 996a371 commit a02dc14
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/services/brawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Brawler } from '@prisma/client';
import { User } from 'discord.js';
import { DEFAULT_AUTH_URL, getUser } from 'knockoutcity-auth-client';
import * as BrawlerDao from '../database/dao/brawler';
import { InternalErrorFailure, Result, Success } from '../result';
import { Failure, InternalErrorFailure, Result, Success } from '../result';

export async function findOrCreateBrawler(
user: User,
Expand All @@ -24,7 +24,18 @@ export async function findOrCreateBrawler(
async function createBrawler(user: User): Promise<Result<Brawler>> {
const userDataResult = await getUser(DEFAULT_AUTH_URL, user.id)
.then(Success)
.catch(InternalErrorFailure);
.catch((error) => {
if (
error.response &&
error.response.status === 400 &&
error.response.data &&
error.response.data.type === 'invalid_account'
) {
return Failure('internal', 'No User for Discord Account found.');
}

return InternalErrorFailure(error);
});

if (userDataResult.type === 'error') {
return userDataResult;
Expand Down

0 comments on commit a02dc14

Please sign in to comment.