From e2768083e422fb2820b420a4ba8c0c4b19c58874 Mon Sep 17 00:00:00 2001 From: Siavash Sefid Rodi Date: Tue, 9 May 2023 15:27:19 +0200 Subject: [PATCH 1/2] added new expected Error INTEGRATION_ACCOUNT_EXPIRED_ERROR. No Logs if CRM Account is expired --- src/models/controller.model.ts | 35 ++++++++++++++++++++++++--- src/models/integration-error.model.ts | 1 + 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/models/controller.model.ts b/src/models/controller.model.ts index 9c03f622..1cc5de7f 100644 --- a/src/models/controller.model.ts +++ b/src/models/controller.model.ts @@ -128,6 +128,14 @@ export class Controller { next(error); return; } + // prevent logging of expired Account errors + else if ( + error instanceof ServerError && + error.message === IntegrationErrorType.INTEGRATION_ACCOUNT_EXPIRED_ERROR + ) { + next(error); + return; + } errorLogger( "Could not get contacts:", @@ -193,7 +201,14 @@ export class Controller { next(error); return; } - + // prevent logging of expired Account errors + else if ( + error instanceof ServerError && + error.message === IntegrationErrorType.INTEGRATION_ACCOUNT_EXPIRED_ERROR + ) { + next(error); + return; + } console.error( `[${anonymizeKey(apiKey)}] Could not create contact`, error || "Unknown" @@ -260,7 +275,14 @@ export class Controller { next(error); return; } - + // prevent logging of expired Account errors + else if ( + error instanceof ServerError && + error.message === IntegrationErrorType.INTEGRATION_ACCOUNT_EXPIRED_ERROR + ) { + next(error); + return; + } console.error("Could not update contact:", error || "Unknown"); next(error); } @@ -310,7 +332,14 @@ export class Controller { next(error); return; } - + // prevent logging of expired Account errors + else if ( + error instanceof ServerError && + error.message === IntegrationErrorType.INTEGRATION_ACCOUNT_EXPIRED_ERROR + ) { + next(error); + return; + } console.error("Could not delete contact:", error || "Unknown"); next(error); } diff --git a/src/models/integration-error.model.ts b/src/models/integration-error.model.ts index a1c79e6d..7361450d 100644 --- a/src/models/integration-error.model.ts +++ b/src/models/integration-error.model.ts @@ -1,6 +1,7 @@ export enum IntegrationErrorType { INTEGRATION_INVALID_URL = "integration/invalid-url", INTEGRATION_REFRESH_ERROR = "integration/refresh-error", + INTEGRATION_ACCOUNT_EXPIRED_ERROR = "integration/account-expired-error", CONTACT_CREATE_ERROR_CONFLICT = "contact/create-error/conflict", CONTACT_CREATE_ERROR_EMAIL_CONFLICT = "contact/create-error/email-conflict", CONTACT_ERROR_TOO_MANY_NUMBERS = "contact/error/too-many-numbers", From 03ae761519608832b0966fd4e542505ee3183665 Mon Sep 17 00:00:00 2001 From: Leona Kuse Date: Wed, 10 May 2023 10:59:27 +0200 Subject: [PATCH 2/2] :recycle: refactor error handling for integration error types --- src/models/controller.model.ts | 66 ++++++++++++---------------------- 1 file changed, 23 insertions(+), 43 deletions(-) diff --git a/src/models/controller.model.ts b/src/models/controller.model.ts index 1cc5de7f..9e481f3d 100644 --- a/src/models/controller.model.ts +++ b/src/models/controller.model.ts @@ -120,18 +120,10 @@ export class Controller { res.status(200).send(responseContacts); } catch (error) { - // prevent logging of refresh errors + // prevent logging of integration errors that are forwarded to the client if ( error instanceof ServerError && - error.message === IntegrationErrorType.INTEGRATION_REFRESH_ERROR - ) { - next(error); - return; - } - // prevent logging of expired Account errors - else if ( - error instanceof ServerError && - error.message === IntegrationErrorType.INTEGRATION_ACCOUNT_EXPIRED_ERROR + error.message in IntegrationErrorType ) { next(error); return; @@ -193,24 +185,18 @@ export class Controller { } } } catch (error) { - // prevent logging of refresh errors + // prevent logging of integration errors that are forwarded to the client if ( error instanceof ServerError && - error.message === IntegrationErrorType.INTEGRATION_REFRESH_ERROR + error.message in IntegrationErrorType ) { next(error); return; } - // prevent logging of expired Account errors - else if ( - error instanceof ServerError && - error.message === IntegrationErrorType.INTEGRATION_ACCOUNT_EXPIRED_ERROR - ) { - next(error); - return; - } - console.error( + + errorLogger( `[${anonymizeKey(apiKey)}] Could not create contact`, + req.providerConfig, error || "Unknown" ); next(error); @@ -267,23 +253,20 @@ export class Controller { } } } catch (error) { - // prevent logging of refresh errors + // prevent logging of integration errors that are forwarded to the client if ( error instanceof ServerError && - error.message === IntegrationErrorType.INTEGRATION_REFRESH_ERROR + error.message in IntegrationErrorType ) { next(error); return; } - // prevent logging of expired Account errors - else if ( - error instanceof ServerError && - error.message === IntegrationErrorType.INTEGRATION_ACCOUNT_EXPIRED_ERROR - ) { - next(error); - return; - } - console.error("Could not update contact:", error || "Unknown"); + + errorLogger( + "Could not update contact:", + req.providerConfig, + error || "Unknown" + ); next(error); } } @@ -324,23 +307,20 @@ export class Controller { } } } catch (error) { - // prevent logging of refresh errors + // prevent logging of integration errors that are forwarded to the client if ( error instanceof ServerError && - error.message === IntegrationErrorType.INTEGRATION_REFRESH_ERROR - ) { - next(error); - return; - } - // prevent logging of expired Account errors - else if ( - error instanceof ServerError && - error.message === IntegrationErrorType.INTEGRATION_ACCOUNT_EXPIRED_ERROR + error.message in IntegrationErrorType ) { next(error); return; } - console.error("Could not delete contact:", error || "Unknown"); + + errorLogger( + "Could not delete contact:", + req.providerConfig, + error || "Unknown" + ); next(error); } }