Add extended error handling for post uploading

pull/5/head
trivernis 5 years ago
parent 5c1cea86eb
commit e1fe543256

@ -63,6 +63,7 @@ export class UploadRoute extends Route {
// Uploads a file to the data directory and returns the filename // Uploads a file to the data directory and returns the filename
this.router.use(async (req, res) => { this.router.use(async (req, res) => {
let uploadConfirmation: IUploadConfirmation; let uploadConfirmation: IUploadConfirmation;
try {
if (req.session.userId) { if (req.session.userId) {
if (req.files.profilePicture) { if (req.files.profilePicture) {
uploadConfirmation = await this.uploadProfilePicture(req); uploadConfirmation = await this.uploadProfilePicture(req);
@ -84,7 +85,13 @@ export class UploadRoute extends Route {
success: false, success: false,
}; };
} }
if (uploadConfirmation.error) { } catch (err) {
uploadConfirmation = {
error: err,
success: false,
};
}
if (uploadConfirmation?.error) {
res.status(httpStatus.BAD_REQUEST); res.status(httpStatus.BAD_REQUEST);
} }
res.json(uploadConfirmation); res.json(uploadConfirmation);

Loading…
Cancel
Save