From 83fc42aecd9382da0bab5948d8beb483ee547e4b Mon Sep 17 00:00:00 2001 From: Nikola Bjelo Date: Thu, 1 Nov 2018 06:48:42 +0100 Subject: [PATCH] Setting up sentry for both logging and error handling (unfinished) --- server/src/errors/index.js | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/server/src/errors/index.js b/server/src/errors/index.js index d97fc3ec5..15b0635a1 100644 --- a/server/src/errors/index.js +++ b/server/src/errors/index.js @@ -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}`