refactor: Refactored middlewares to use RequestError

Refactored middlewares to use RequestError rather than using
`try {...}catch (err){...}`. With this change it's possible to manage
all error details within one place.

Added:
- Added Sentry.captureException to Error Handler
This commit is contained in:
Hüseyin Berke Bütün
2022-12-22 01:42:02 +01:00
parent bd9041a62c
commit 6f5d7a831b
13 changed files with 156 additions and 199 deletions

View File

@@ -1,6 +1,7 @@
import * as Sentry from '@sentry/node';
import { Request, Response, NextFunction } from 'express';
import { validateMembership } from '../helpers/membership';
import { UnauthorizedRequestError } from '../utils/errors';
type req = 'params' | 'body' | 'query';
@@ -36,11 +37,7 @@ const requireWorkspaceAuth = ({
return next();
} catch (err) {
Sentry.setUser(null);
Sentry.captureException(err);
return res.status(401).send({
error: 'Failed workspace authorization'
});
return next(UnauthorizedRequestError({message: 'Unable to authenticate workspace'}))
}
};
};