Skip to content

Commit abed9b9

Browse files
committed
changing error type thrown on bad request
1 parent 5800e73 commit abed9b9

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

src/constants/responses.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,7 @@ export const ROLE_REMOVED = "Role Removed successfully";
3030

3131
export const ROLE_FETCH_FAILED =
3232
"Oops! We are experiencing an issue fetching roles.";
33+
34+
export const BAD_REQUEST = {
35+
error: "Oops! This is not a proper request.",
36+
};

src/controllers/guildRoleHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export async function getGuildRoleByRoleNameHandler(
111111
}
112112

113113
if (!roleName) {
114-
return new JSONResponse(response.NOT_FOUND, { status: 404 });
114+
return new JSONResponse(response.BAD_REQUEST, { status: 404 });
115115
}
116116
try {
117117
await verifyAuthToken(authHeader, env);

tests/unit/handlers/guildRoleHandler.test.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ const getGuildRolesSpy = jest.spyOn(guildRoleUtils, "getGuildRoles");
2020
const getGuildRoleByNameSpy = jest.spyOn(guildRoleUtils, "getGuildRoleByName");
2121

2222
describe("get roles", () => {
23-
beforeEach(() => {
24-
jest.resetAllMocks();
25-
});
2623
it("should return a instance of JSONResponse", async () => {
2724
const mockRequest = generateDummyRequestObject({ url: "/roles" });
2825
const response = await getGuildRolesHandler(mockRequest, guildEnv);
@@ -148,7 +145,7 @@ describe("get role by role name", () => {
148145
expect(jsonResponse).toEqual(responseConstants.BAD_SIGNATURE);
149146
});
150147

151-
it("should return Not Found error if no roleName is not provided", async () => {
148+
it("should return BAD REQUEST error if roleName is not provided", async () => {
152149
getGuildRoleByNameSpy.mockResolvedValueOnce(undefined);
153150
const mockRequest = generateDummyRequestObject({
154151
url: "/roles",
@@ -162,7 +159,7 @@ describe("get role by role name", () => {
162159
);
163160
const jsonResponse: { error: string } = await response.json();
164161
expect(response.status).toBe(404);
165-
expect(jsonResponse).toEqual(responseConstants.NOT_FOUND);
162+
expect(jsonResponse).toEqual(responseConstants.BAD_REQUEST);
166163
});
167164

168165
it("should return not found object if there is no roles with given name in guild", async () => {

0 commit comments

Comments
 (0)