Skip to content

Commit

Permalink
Merge pull request #14 from Ba3a-G/response-fix
Browse files Browse the repository at this point in the history
Update error messages in controllers
  • Loading branch information
BRAVO68WEB authored Jan 19, 2024
2 parents 4b198de + d0a4966 commit 534d3f4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
10 changes: 5 additions & 5 deletions packages/api/controllers/challenges.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class ChallengeController extends ChallengeService {
message: error.message
}, 404) : ctx.json({
status: 500,
message: error.message
message: "Something went wrong, come to us :)"
}, 500);
}
};
Expand All @@ -91,16 +91,16 @@ export class ChallengeController extends ChallengeService {
});
return ctx.json({
status: 200,
message: data
data
});
}
catch (error: any) {
switch (error.message) {
case "Wrong flag": {
return ctx.json({
status: 418,
status: 401,
message: error.message
}, 418);
}, 401);
}
case "User not in team": {
return ctx.json({
Expand Down Expand Up @@ -131,7 +131,7 @@ export class ChallengeController extends ChallengeService {
default: {
return ctx.json({
status: 500,
message: error.message
message: "Something went wrong, come to us :)"
}, 500);
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/api/controllers/stats.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class StatsControtoller extends StatsService {
message: error.message
}, 404) : ctx.json({
status: 500,
message: error.message
message: "Something went wrong, come to us :)"
}, 500);
}
};
Expand All @@ -37,7 +37,7 @@ export class StatsControtoller extends StatsService {
message: error.message
}, 404) : ctx.json({
status: 500,
message: error.message
message: "Something went wrong, come to us :)"
}, 500);
}
};
Expand Down
17 changes: 8 additions & 9 deletions packages/api/controllers/teams.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ export class TeamController extends TeamService {
});
}
catch (error: any) {
// log it
console.log(error.message);
return ctx.json({
status: 500,
message: error.message
message: "Something went wrong, come to us :)"
}, 500);
}
};
Expand All @@ -30,7 +32,7 @@ export class TeamController extends TeamService {
});
}
catch (error: any) {
return error.message === "Team not found" ? ctx.json({status: 404, message: error.message}, 404) : ctx.json({status: 500, message: error.message}, 500);
return error.message === "Team not found" ? ctx.json({status: 404, message: error.message}, 404) : ctx.json({status: 500, message: "Something went wrong, come to us :)"}, 500);
}
};

Expand All @@ -51,7 +53,7 @@ export class TeamController extends TeamService {
switch (error.message) {
case "Invalid join code": { return ctx.json({ status: 400, message: error.message }, 400); }
case "Team is full": { return ctx.json({ status: 403, message: error.message }, 403); }
default: { return ctx.json({ status: 500, message: error.message }, 500); }
default: { return ctx.json({ status: 500, message: "Something went wrong, come to us :)" }, 500); }
}
}
};
Expand All @@ -74,10 +76,10 @@ export class TeamController extends TeamService {
const data = await this.whomaiS(userTeamID);
return ctx.json({ status: 200, message: data });
}
catch (error: any) {
catch {
return ctx.json({
status: 500,
message: error.message
message: "Something went wrong, come to us :)"
}, 500);
}
};
Expand Down Expand Up @@ -110,10 +112,7 @@ export class TeamController extends TeamService {
return ctx.json({ status: 200, message: data });
}
catch (error: any) {
return ctx.json({
status: 500,
message: error.message
}, 500);
return error.message === "Invalid request" ? ctx.json({status: 400, message: "Bad request"}, 400) : ctx.json({status: 500, message: "Something went wrong, come to us :)"}, 500);
}
};
}
8 changes: 4 additions & 4 deletions packages/api/controllers/users.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ export class UserController extends UserService {
try {
const reqBody = await ctx.req.json();
const data = await this.verifyUserS(reqBody);
return ctx.json({ status: 200, message: data });
return ctx.json({ status: 200, message: data.message });
}
catch (error: any) {
return error.message === "Invalid OTP" ? ctx.json({status: 401, message: error.message}, 401) : ctx.json({status: 500, message: error.message}, 500);
return error.message === "Invalid OTP" ? ctx.json({status: 401, message: error.message}, 401) : ctx.json({status: 500, message: "Something went wrong. Come to us :)"}, 500);
}
};

Expand All @@ -35,7 +35,7 @@ export class UserController extends UserService {
switch (error.message) {
case "Invalid credentials": { return ctx.json({ status: 401, message: error.message }, 401); }
case "Email not verified": { return ctx.json({ status: 403, message: error.message }, 403); }
default: { return ctx.json({ status: 500, message: error.message }, 500); }
default: { return ctx.json({ status: 500, message: "Something went wrong. Come to us:)"}, 500); }
}
}
};
Expand All @@ -46,7 +46,7 @@ export class UserController extends UserService {
return ctx.json({ status: 200, message: data }, 200);
}
catch (error: any) {
return error.message === "User not found" ? ctx.json({status: 404, message: error.message}, 404) : ctx.json({status: 500, message: error.message}, 500);
return error.message === "User not found" ? ctx.json({status: 404, message: error.message}, 404) : ctx.json({status: 500, message: "Something went wrong. Come to us :)"}, 500);
}
};
}

0 comments on commit 534d3f4

Please sign in to comment.