Skip to content

Commit

Permalink
fix: 401 not 400
Browse files Browse the repository at this point in the history
  • Loading branch information
HollaG committed Nov 14, 2024
1 parent bffd33a commit a60dce3
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 31 deletions.
4 changes: 2 additions & 2 deletions collaboration-service/src/errors/ForbiddenError.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import BaseError from './BaseError.js';

class ForbiddenError extends BaseError {
constructor(message) {
super(403, message);
super(400, message);
this.name = 'ForbiddenError';
this.statusCode = 403;
this.statusCode = 400;
}
}

Expand Down
2 changes: 1 addition & 1 deletion collaboration-service/src/errors/InvalidArgumentError.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class InvalidArgumentError extends BaseError {
constructor(message) {
super(500, message);
this.name = 'InvalidArgumentError';
this.statusCode = 403;
this.statusCode = 400;
}
}

Expand Down
4 changes: 2 additions & 2 deletions collaboration-service/src/errors/InvalidQueryParamError.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import BaseError from './BaseError.js';

class InvalidQueryParamError extends BaseError {
constructor(message) {
super(401, message);
super(400, message);
this.name = 'InvalidQueryParamError';
this.statusCode = 401;
this.statusCode = 400;
}
}

Expand Down
4 changes: 2 additions & 2 deletions collaboration-service/src/errors/RoomCapacityError.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import BaseError from './BaseError.js';

class RoomCapacityError extends BaseError {
constructor(message) {
super(401, message);
super(400, message);
this.name = 'RoomCapacityError';
this.statusCode = 401;
this.statusCode = 400;
}
}

Expand Down
4 changes: 2 additions & 2 deletions collaboration-service/src/errors/RoomNotEmptyError.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import BaseError from './BaseError.js';

class RoomNotEmptyError extends BaseError {
constructor(message) {
super(401, message);
super(400, message);
this.name = 'RoomNotEmptyError';
this.statusCode = 401;
this.statusCode = 400;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import BaseError from './BaseError.js';

class UserAlreadyFoundInRoomError extends BaseError {
constructor(message) {
super(401, message);
super(400, message);
this.name = 'UserAlreadyFoundInRoomError';
this.statusCode = 401;
this.statusCode = 400;
}
}

Expand Down
4 changes: 2 additions & 2 deletions collaboration-service/src/errors/UserDeregistrationError.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import UserRegistrationError from './UserRegistrationError.js';

class UserDeregistrationError extends UserRegistrationError {
constructor(message) {
super(401, message);
super(400, message);
this.name = 'UserDeregistrationError';
this.statusCode = 401;
this.statusCode = 400;
}
}

Expand Down
4 changes: 2 additions & 2 deletions collaboration-service/src/errors/UserRegistrationError.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import BaseError from './BaseError.js';

class UserRegistrationError extends BaseError {
constructor(message) {
super(401, message);
super(400, message);
this.name = 'UserRegistrationError';
this.statusCode = 401;
this.statusCode = 400;
}
}

Expand Down
20 changes: 10 additions & 10 deletions collaboration-service/src/session/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const createRoom = async (request, response, next) => {
question === null ||
question === undefined
) {
return response.status(401).json({
statusCode: 401,
return response.status(400).json({
statusCode: 400,
message: 'Unable to create room as no users or questions are defined',
});
}
Expand Down Expand Up @@ -85,8 +85,8 @@ const getRoomDetails = async (request, response, next) => {
console.log('users:', users);

if (users === null) {
return response.status(401).json({
statusCode: 401,
return response.status(400).json({
statusCode: 400,
message: 'Room cannot be found',
});
}
Expand Down Expand Up @@ -175,8 +175,8 @@ const getUserDetails = async (request, response, next) => {
const roomDetails = LocalClient.getDocByUser(userId);

if (roomDetails === null) {
return response.status(401).json({
statusCode: 401,
return response.status(400).json({
statusCode: 400,
message: 'User ID is invalid',
});
}
Expand Down Expand Up @@ -211,8 +211,8 @@ const registerUser = async (request, response, next) => {
userId === undefined ||
userId === null
) {
return response.status(401).json({
statusCode: 401,
return response.status(400).json({
statusCode: 400,
message: 'Cannot register user as userId or roomId is missing',
});
}
Expand Down Expand Up @@ -251,8 +251,8 @@ const deregisterUser = async (request, response, next) => {
userId === undefined ||
userId === null
) {
return response.status(401).json({
statusCode: 401,
return response.status(400).json({
statusCode: 400,
message: 'Cannot register user as userId or roomId is missing',
});
}
Expand Down
12 changes: 6 additions & 6 deletions collaboration-service/test/test-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('Collaboration Service API', () => {
.post('/api/collaboration-service/create-room')
.set({ Cookie: `accessToken=${token}` })
.send({ question: 'question' })
.expect(401)
.expect(400)
.expect('Content-Type', /json/);

assert.equal(
Expand All @@ -59,7 +59,7 @@ describe('Collaboration Service API', () => {
.post('/api/collaboration-service/create-room')
.set({ Cookie: `accessToken=${token}` })
.send({ users: ['user1', 'user2'] })
.expect(401)
.expect(400)
.expect('Content-Type', /json/);

assert.equal(
Expand Down Expand Up @@ -87,7 +87,7 @@ describe('Collaboration Service API', () => {
.post('/api/collaboration-service/create-room')
.set({ Cookie: `accessToken=${token}` })
.send({ question: 'question 2', users: ['userabc', 'userkmn'] })
.expect(401)
.expect(400)
.expect('Content-Type', /json/);

assert.equal(test.body.message, 'Users belong in seperate rooms');
Expand Down Expand Up @@ -163,7 +163,7 @@ describe('Collaboration Service API', () => {
const result = await request(app)
.get('/api/collaboration-service/rooms/asdnasdsa')
.set({ Cookie: `accessToken=${token}` })
.expect(401)
.expect(400)
.expect('Content-Type', /json/);

assert.equal(result.body.message, 'Room cannot be found');
Expand Down Expand Up @@ -242,7 +242,7 @@ describe('Collaboration Service API', () => {
const result = await request(app)
.get('/api/collaboration-service/users')
.set({ Cookie: `accessToken=${token}` })
.expect(401)
.expect(400)
.expect('Content-Type', /json/);

assert.equal(result.body.message, 'User ID is invalid');
Expand All @@ -252,7 +252,7 @@ describe('Collaboration Service API', () => {
const result = await request(app)
.get('/api/collaboration-service/users?userId=asdnasdsa')
.set({ Cookie: `accessToken=${token}` })
.expect(401)
.expect(400)
.expect('Content-Type', /json/);

assert.equal(result.body.message, 'User ID is invalid');
Expand Down

0 comments on commit a60dce3

Please sign in to comment.