Setting up sentry for both logging and error handling (unfinished)

This commit is contained in:
Nikola Bjelo committed 2018-11-01 06:48:42 +01:00
1 parent 205b451495
commit 83fc42aecd
1 file changed
+26 -4
+26 -4
View File
@@ -1,22 +1,44 @@
export class AuthentificationError extends Error {
import * as Sentry from '@sentry/node';
class ClientError extends Error {
constructor(args) {
super(args);
Sentry.configureScope((scope) => {
scope.setLevel('info');
});
Sentry.captureException(this);
}
}
class ServerError extends Error {
constructor(args) {
super(args);
Sentry.configureScope((scope) => {
scope.setLevel('error');
});
Sentry.captureException(this);
}
}
export class AuthentificationError extends ClientError {
code = 401
message = 'Autentification not found, you have to be authentificated to perform this action'
}
export class DatabaseError extends Error {
export class DatabaseError extends ClientError {
code = 404
message = `Ressource not found : ${this.message}`
}
export class WrongArgumentsError extends Error {
export class WrongArgumentsError extends ClientError {
code = 400
message = `Wrong arguments : ${this.message}`
}
export class ServiceUnavailableError extends Error {
export class ServiceUnavailableError extends ServerError {
code = 503
message = `At least one service is unresponding ${this.message}`