mirror of
https://github.com/ets-cfuhrman-pfe/EvalueTonSavoir.git
synced 2025-08-11 21:23:54 -04:00
Correction
This commit is contained in:
parent
9ece28a86b
commit
545d6551f6
4 changed files with 27 additions and 39 deletions
20
.gitignore
vendored
20
.gitignore
vendored
|
|
@ -122,25 +122,13 @@ dist
|
|||
# Stores VSCode versions used for testing VSCode extensions
|
||||
.vscode-test
|
||||
|
||||
.env
|
||||
launch.json
|
||||
|
||||
# yarn v2
|
||||
.yarn/cache
|
||||
.yarn/unplugged
|
||||
.yarn/build-state.yml
|
||||
.yarn/install-state.gz
|
||||
.pnp.*
|
||||
db-backup/
|
||||
|
||||
.V5/
|
||||
.EvaluateTonSavoir/
|
||||
config/
|
||||
applicationhost.config
|
||||
FileContentIndex/
|
||||
*.vsidx
|
||||
v17/
|
||||
.WSuO/
|
||||
DocumentLayout.backup.json
|
||||
DocumentLayout.json
|
||||
ProjectSettings.json
|
||||
slnx.sqlite
|
||||
slnx.sqlite-journal
|
||||
VSWorkspaceState.json
|
||||
db-backup/
|
||||
|
|
@ -17,7 +17,7 @@ class RoomsController {
|
|||
create = async (req, res, next) => {
|
||||
try {
|
||||
if (!req.user || !req.user.userId) {
|
||||
throw new AppError("Utilisateur non authentifié", 401);
|
||||
throw new AppError(MISSING_REQUIRED_PARAMETER);
|
||||
}
|
||||
|
||||
const { title } = req.body;
|
||||
|
|
@ -30,9 +30,7 @@ class RoomsController {
|
|||
const roomExists = await this.rooms.roomExists(normalizedTitle);
|
||||
|
||||
if (roomExists) {
|
||||
const error = new Error("Room already exists");
|
||||
error.statusCode = 409;
|
||||
throw error;
|
||||
throw new AppError(ROOM_ALREADY_EXISTS);
|
||||
}
|
||||
|
||||
const result = await this.rooms.create(normalizedTitle, req.user.userId);
|
||||
|
|
@ -42,17 +40,14 @@ class RoomsController {
|
|||
roomId: result.insertedId,
|
||||
});
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
if (error.message === "Room already exists") {
|
||||
return next(new AppError(ROOM_ALREADY_EXISTS));
|
||||
}
|
||||
}
|
||||
|
||||
next(error);
|
||||
next(
|
||||
error instanceof AppError
|
||||
? error
|
||||
: new AppError({ message: error.message, code: 500 })
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
getUserRooms = async (req, res, next) => {
|
||||
try {
|
||||
const rooms = await this.rooms.getUserRooms(req.user.userId);
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
class AppError extends Error {
|
||||
constructor (errorCode) {
|
||||
super(errorCode.message)
|
||||
this.statusCode = errorCode.code;
|
||||
this.isOperational = true; // Optional: to distinguish operational errors from programming errors
|
||||
super(errorCode.message);
|
||||
this.statusCode = errorCode.code;
|
||||
this.isOperational = true;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = AppError;
|
||||
}
|
||||
|
||||
module.exports = AppError;
|
||||
|
||||
|
|
@ -9,11 +9,15 @@ const errorHandler = (error, req, res, _next) => {
|
|||
code: error.statusCode
|
||||
});
|
||||
}
|
||||
|
||||
return res.status(500).json({
|
||||
message: "Erreur technique",
|
||||
code: 500
|
||||
});
|
||||
|
||||
logError(error.stack);
|
||||
return res.status(505).send("Oups! We screwed up big time. ┻━┻ ︵ヽ(`Д´)ノ︵ ┻━┻");
|
||||
};
|
||||
|
||||
const logError = (error) => {
|
||||
const time = new Date();
|
||||
var log_file = fs.createWriteStream(__dirname + '/../debug.log', {flags : 'a'});
|
||||
log_file.write(time + '\n' + error + '\n\n');
|
||||
}
|
||||
|
||||
module.exports = errorHandler;
|
||||
|
|
|
|||
Loading…
Reference in a new issue