import { HttpStatus } from '@nestjs/common'; import { ErrorType } from './enums'; import { ErrorCodeDetails, ErrorCodeMapInterface } from './interfaces'; import { AppLogger } from '../../../logger'; import { ErrorCode } from './enums'; export class ErrorCodeResolver { private static readonly TAG: string = `ErrorCodeResolver`; private static readonly ErrorCodeMap: ErrorCodeMapInterface = { [ErrorType.UNAUTHORIZED]: { /* Guards */ [ErrorCode.NO_AUTHORIZATION_ON_HEADER]: { message: 'No Permissions property on request header', status: HttpStatus.UNAUTHORIZED, }, [ErrorCode.INVALID_TOKEN]: { message: 'Invalid access token provided', status: HttpStatus.UNAUTHORIZED, }, [ErrorCode.UNAUTHORIZED_PROJECT]: { message: 'Account does not authorized for this project', status: HttpStatus.UNAUTHORIZED, }, [ErrorCode.PERMISSION_GUARD_FAILED]: { message: 'Failed to get user project', status: HttpStatus.UNAUTHORIZED, }, [ErrorCode.UNAUTHORIZED_PERMISSION]: { message: 'Invalid user authorization', status: HttpStatus.FORBIDDEN, }, [ErrorCode.INVALID_ACLS]: { message: 'Invalid ACLs', status: HttpStatus.FORBIDDEN, }, }, [ErrorType.UNKNOWN]: { /* UNKNOWN */ [ErrorCode.UNKNOWN]: { message: 'Server handling with an unknown error', status: HttpStatus.INTERNAL_SERVER_ERROR, }, }, [ErrorType.HTTP]: { /* Connection Lost */ [ErrorCode.CONNECTION_LOST]: { message: 'Lost connection with Service', status: HttpStatus.INTERNAL_SERVER_ERROR, }, /* Auth */ [ErrorCode.INVALID_CLIENT]: { message: 'Invalid client id', hideMessage: true, status: HttpStatus.UNAUTHORIZED, }, [ErrorCode.UNHANDLED_GRANT_TYPE]: { message: 'Unhandled grant type', hideMessage: true, status: HttpStatus.UNAUTHORIZED, }, [ErrorCode.ACCESS_TOKEN]: { message: 'Failed to generate access token', hideMessage: true, status: HttpStatus.BAD_REQUEST, }, [ErrorCode.GET_USER_AUTH]: { message: 'Failed to get user by credentials', hideMessage: true, status: HttpStatus.BAD_REQUEST, }, [ErrorCode.GET_USER_BY_REFRESH_TOKEN]: { message: 'Failed to get user by refresh token', hideMessage: true, status: HttpStatus.FORBIDDEN, }, [ErrorCode.VERIFY_AUTH_CODE]: { message: 'Failed to verify auth token', hideMessage: true, status: HttpStatus.FORBIDDEN, }, [ErrorCode.REDIRECT_URI]: { message: `Redirect uri don't match`, hideMessage: true, status: HttpStatus.FORBIDDEN, }, [ErrorCode.MFA_TOKEN]: { message: 'MFA token is missing', hideMessage: true, status: HttpStatus.UNAUTHORIZED, }, [ErrorCode.EMAIL_FAILED]: { message: 'Failed to sent an email', hideMessage: true, status: HttpStatus.UNAUTHORIZED, }, [ErrorCode.USER_IS_BLOCK]: { message: 'User is block - maximum otp attempted', status: HttpStatus.UNAUTHORIZED, }, [ErrorCode.JWT_EXPIRED]: { message: 'JWT - expired', status: HttpStatus.UNAUTHORIZED, }, [ErrorCode.USER_ALREADY_INVITED]: { message: 'User already invited', status: HttpStatus.UNAUTHORIZED, }, [ErrorCode.DECODE_INVITATION_TOKEN]: { message: 'Failed to decode invitation token', status: HttpStatus.UNAUTHORIZED, }, [ErrorCode.OTP_VALIDATION]: { message: 'Failed to validated otp code', status: HttpStatus.UNAUTHORIZED, }, [ErrorCode.UPDATE_USER_AUTH]: { message: 'Failed to update user', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.MFA_TOKEN_DECODED_FAILED]: { message: 'Failed to decode mfa token', status: HttpStatus.UNAUTHORIZED, }, [ErrorCode.GENERATE_OTP]: { message: 'Failed to generate otp code', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.UPDATE_OTP]: { message: 'Failed to update otp code', status: HttpStatus.UNAUTHORIZED, }, [ErrorCode.INVALID_RESPONSE_TYPE]: { message: 'Invalid response type', status: HttpStatus.UNAUTHORIZED, }, [ErrorCode.AUTH_CODE]: { message: 'Failed to generate auth code', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.MFA_TOKEN_EXPIRED]: { message: 'Mfa token expired', status: HttpStatus.UNAUTHORIZED, }, [ErrorCode.JWKS_FAIL]: { message: 'Failed to get jwks data', status: HttpStatus.UNAUTHORIZED, }, [ErrorCode.GET_SERVICE_ACCOUNT_BY_REFRESH_TOKEN]: { message: 'Failed to get service account by refresh token', status: HttpStatus.UNAUTHORIZED, }, [ErrorCode.GET_SERVICE_ACCOUNT_AUTH]: { message: 'Failed to get service account', status: HttpStatus.UNAUTHORIZED, }, [ErrorCode.SERVICE_ACCOUNT_REFRESH_TOKEN]: { message: 'Failed to generate service account refresh token', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.SERVICE_ACCOUNT_ACCESS_TOKEN]: { message: 'Failed to generate service account access token', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.SERVICE_ACCOUNT_CIPHER]: { message: 'Failed to get service account cipher key', status: HttpStatus.UNAUTHORIZED, }, [ErrorCode.SERVICE_ACCOUNT_DECIPHER]: { message: 'Failed to decipher service account key', status: HttpStatus.UNAUTHORIZED, }, [ErrorCode.SERVICE_ACCOUNT_TOKEN_VERIFY]: { message: 'Failed to verify service account token', status: HttpStatus.UNAUTHORIZED, }, [ErrorCode.RESET_PASSWORD_TOKEN]: { message: 'Failed to generate reset password token', status: HttpStatus.UNAUTHORIZED, }, [ErrorCode.DECODE_RESET_PASSWORD_TOKEN]: { message: 'Failed to decode reset password token', status: HttpStatus.UNAUTHORIZED, }, [ErrorCode.RESET_USER_PASSWORD]: { message: 'Failed to reset user password', status: HttpStatus.UNAUTHORIZED, }, [ErrorCode.INACTIVE_USER]: { message: 'User inactive', status: HttpStatus.UNAUTHORIZED, }, [ErrorCode.SUSPENDED_USER]: { message: 'User suspended', status: HttpStatus.UNAUTHORIZED, }, [ErrorCode.INVITE_USER]: { message: 'Failed to invite user', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.INVITATION_LINK]: { message: 'Failed to generate user invitation link', status: HttpStatus.INTERNAL_SERVER_ERROR, }, /* Account */ [ErrorCode.SERVICE_ACCOUNT_EXIST]: { message: 'Service Account already exist', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.CREATE_SERVICE_ACCOUNT]: { message: 'Failed to create Service Account', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.GENERATE_SERVICE_ACCOUNT_KEY]: { message: 'Failed to generate Service Account key', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.CREATE_SERVICE_ACCOUNT_KEY]: { message: 'Failed to create Service Account key', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.GET_SERVICE_ACCOUNT_BY_ID]: { message: 'Failed to get Service Account by id', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.UPDATE_SERVICE_ACCOUNT_BY_ID]: { message: 'Failed to update Service Account by id', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.GET_SERVICE_ACCOUNT_KEY]: { message: 'Failed to get Service Account key', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.MAP_SERVICE_ACCOUNT_KEY]: { message: 'Failed to map Service Account key to Service Account', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.DELETE_SERVICE_ACCOUNT_BY_ID]: { message: 'Failed to delete Service Account by id', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.DELETE_MANY_SERVICE_ACCOUNT_BY_ID]: { message: 'Failed to delete many Service Accounts by id', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.NO_SERVICE_ACCOUNT_KEY_ID]: { message: 'Failed to get service account, No key id received', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.GET_SERVICE_ACCOUNT_ID_BY_KEY_ID]: { message: 'Failed to get service account id by key id', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.GET_SERVICE_ACCOUNT_BY_PROJECT]: { message: 'Failed to get service account by project short id', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.EXTRACT_SERVICE_ACCOUNT_ID]: { message: 'Failed to get extract service account id', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.GET_USER_BY_FIELDS]: { message: 'Failed to get user details', status: HttpStatus.UNAUTHORIZED, }, [ErrorCode.MAP_SERVICE_ACCOUNT_TO_KEY]: { message: 'Failed to map service account to key', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.UPDATE_SERVICE_ACCOUNT_KEY]: { message: 'Failed to update service account key', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.GET_MANY_SERVICE_ACCOUNT_BY_EMAIL]: { message: 'Failed to get many service accounts by email', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.SAVE_SERVICE_ACCOUNT_PROJECT_ROLE]: { message: 'Failed to update service accounts project roles', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.DELETE_SERVICE_ACCOUNT_PROJECT_ROLE]: { message: 'Failed to delete service accounts project roles', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.GET_USER_PROJECTS]: { message: 'Failed to get user projects by user id', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.CREATE_USER]: { message: 'Failed to create user', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.DELETE_USER_AFTER_INVITATION_FAILED]: { message: 'Failed to delete user after invitation failed', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.UPDATE_USER_BY_ID]: { message: 'Failed to update user by id', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.UPDATE_USER_PROJECT_ROLE]: { message: 'Failed to update user project roles', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.UPDATE_USER_SYSTEM_ROLE]: { message: 'Failed to update user system roles', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.DELETE_USER_BY_ID]: { message: 'Failed to delete user by id', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.DELETE_MANY_USERS_BY_ID]: { message: 'Failed to delete many users by id', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.UPDATE_USER_LANGUAGE]: { message: 'Failed to delete many users by id', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.GET_USER_ROLES_BY_PROJECT]: { message: 'Failed to get users roles by project', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.GET_USER_BY_PROJECT_ROLE]: { message: 'Failed to get users by project role', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.GET_MANY_USERS_BY_ID]: { message: 'Failed to get many users by id', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.GET_ALL_USERS]: { message: 'Failed to get all users', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.GET_ALL_PROJECT_ROLES]: { message: 'Failed to get all account project roles', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.GET_ALL_SYSTEM_ROLES]: { message: 'Failed to get all account system roles', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.MAP_USERS_TO_ROLES]: { message: 'Failed to map users to roles', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.NO_USERS_RECEIVED]: { message: 'No users received', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.DELETE_USER_PROJECT_ROLES]: { message: 'Failed to delete user project roles', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.GET_USER_BY_ID]: { message: 'Failed to get user by id', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.INVITATION_FAILED]: { message: 'Failed to send invitation to user', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.GET_USER_FEATURE_ONBOARD]: { message: 'Failed to get user feature onboards', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.SET_USER_FEATURE_ONBOARD]: { message: 'Failed to set user feature onboards', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.ACCOUNT_UNKNOWN_ERROR]: { message: 'Unknown error from Account Service', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.GET_USER_BY_CREDENTIALS]: { message: 'Failed to verify user by credentials', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.UPDATE_USER_STATUS]: { message: 'Failed update user status', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.GET_USER_PROJECT_ROLES]: { message: 'Failed to get user project roles', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.GET_USER_SYSTEM_ROLES]: { message: 'Failed to get user system roles', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.USER_EXIST]: { message: 'Failed to create user, user already exist', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.DELETE_USER_PROJECT_TAG]: { message: 'Failed to delete user project tag', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.UPDATE_USER_PROJECT_TAG]: { message: 'Failed to update user project tag', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.GET_PROJECT_GROUP]: { message: 'Failed to get project groups', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.CREATE_GROUP]: { message: 'Failed to create groups. Group name or email already exist', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.UPDATE_GROUP]: { message: 'Failed to update groups. Group name or email already exist', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.DELETE_GROUP]: { message: 'Failed to delete groups by id', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.DELETE_GROUP_PROJECT_ROLE]: { message: 'Failed to delete groups project role', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.GET_USER_ACL]: { message: 'Failed to get user Acls', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.CREATE_USER_ACL_FOR_GROUP]: { message: 'Failed to create group', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.CREATE_GRANT_ACCESS]: { message: 'Failed to create grant access', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.GET_USERS_BY_EMAIL]: { message: 'Failed to get users by email', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.DELETE_USERS_FROM_PROJECT]: { message: 'Failed to delete users from project', status: HttpStatus.BAD_REQUEST, }, /* Agent */ [ErrorCode.AGENT_EXIST]: { message: 'Agent already exist', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.AGENT_BAD_PARAMS]: { message: 'Missing Parmas', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.GET_AGENTS_BY_SERVICE_ACCOUNT_KEY]: { message: 'Failed to get agents by service account keys', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.GET_AGENTS_BY_ID]: { message: 'Failed to get agents by id', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.GET_AGENTS_BY_PROJECT]: { message: 'Failed to get agents by project short id', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.UPDATE_AGENT_BY_ID]: { message: 'Failed to update Agent by id', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.DELETE_AGENT_BY_ID]: { message: 'Failed to delete Agent by id', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.DELETE_MANY_AGENT_BY_ID]: { message: 'Failed to delete many Agents by id', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.GET_AGENT_AUDIT_TRAILS]: { message: 'Failed to get Agent audit trails', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.AGENT_UNKNOWN_ERROR]: { message: 'Unknown error from Agent Service', status: HttpStatus.INTERNAL_SERVER_ERROR, }, /* Application */ [ErrorCode.DECODE_USER_ACCESS_TOKEN]: { message: 'Failed to decode user access token', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.GET_ALL_APPS]: { message: 'Failed to get all applications', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.ASSIGN_APP_TO_PROJECT]: { message: 'Failed to assign project to application', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.GET_PROJECT_APPS]: { message: 'Failed to get project applications', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.MAP_APPS_ID]: { message: 'Failed to map applications id', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.GET_APPS_BY_ID]: { message: 'Failed to get applications by id', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.PIN_APP]: { message: 'Failed to pin application', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.UNPIN_APP]: { message: 'Failed to unpin application', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.ASSIGN_USER_TO_APP]: { message: 'Failed assign users to application', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.GET_USER_APPS]: { message: 'Failed to get user applications', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.DELETE_USER_APPS]: { message: 'Failed to delete user applications', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.LOCK_USER_APPS]: { message: 'Failed to lock user applications', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.UNLOCK_USER_APPS]: { message: 'Failed to unlock user applications', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.GET_APP_CATEGORIES]: { message: 'Failed to get applications categories', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.APP_UNKNOWN_ERROR]: { message: 'Unknown error from Application Service', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.DELETE_USER_DEFAULT_APP]: { message: 'Failed to delete user default application', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.UPDATE_USER_DEFAULT_APP]: { message: 'Failed to update user default application', status: HttpStatus.INTERNAL_SERVER_ERROR, }, /* Facility */ [ErrorCode.FACILITY_DECODE_USER_ACCESS_TOKEN]: { message: 'Failed to decode user access token', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.GET_DASHBOARD_CATEGORIES]: { message: 'Failed to get dashboard categories', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.GET_DASHBOARD_VIEW]: { message: 'Failed to get dashboard view', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.GET_TABLEAU_TICKET]: { message: 'Failed to get ticket from tableau server', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.FACILITY_UNKNOWN_ERROR]: { message: 'Unknown error from Facility Intelligence Service', status: HttpStatus.INTERNAL_SERVER_ERROR, }, /* Project */ [ErrorCode.GET_ALL_PROJECTS]: { message: 'Failed to get all projects', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.GET_PROJECT_BY_ID]: { message: 'Failed to project by id', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.CREATE_PROJECT]: { message: 'Failed to create project', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.UPDATE_PROJECT_BY_ID]: { message: 'Failed to update project by id', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.DELETE_PROJECT_BY_ID]: { message: 'Failed to delete project by id', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.GET_USER_PROJECT]: { message: 'Failed to get user project', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.PROJECT_UNKNOWN_ERROR]: { message: 'Unknown error from Project Service', status: HttpStatus.INTERNAL_SERVER_ERROR, }, /* Site */ [ErrorCode.GET_AGENT_SITE]: { message: 'Failed to get agent site', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.GET_PROJECT_DEVICES]: { message: 'Failed to get project devices', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.GET_DEVICE_BY_ID]: { message: 'Failed to get device by id', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.GET_DEVICE_SENSORS]: { message: 'Failed to get device sensors', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.GET_PROJECT_SENSORS]: { message: 'Failed to get project sensors', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.ALARM_STRUCTURE]: { message: 'Failed to send alarm structure data', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.DEVICE_STRUCTURE]: { message: 'Failed to send device structure data', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.GLOBAL_STRUCTURE]: { message: 'Failed to send global structure data', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.EVENT_STRUCTURE]: { message: 'Failed to send event structure data', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.SYSTEM_STRUCTURE]: { message: 'Failed to send system structure data', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.GET_PROJECT_SYSTEMS]: { message: 'Failed to get project systems', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.GET_PROJECT_LOCATIONS]: { message: 'Failed to get project locations', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.GET_ROOT_SITE_HIERARCHY]: { message: 'Failed to get root site hierarchy', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.GET_SITE_HIERARCHY_TREE]: { message: 'Failed to get full site hierarchy tree', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.SAVE_SITE_HIERARCHY_HISTORY]: { message: 'Failed to save site hierarchy history', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.SAVE_NEW_SITE_HIERARCHY_TREE]: { message: 'Failed to save new site hierarchy tree', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.GET_NEW_SITE_HIERARCHY_TREE]: { message: 'Failed to get new site hierarchy tree', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.CREATE_SITE]: { message: 'Failed to create site', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.GET_PROJECT_DEVICE_CATEGORY]: { message: 'Failed to get device categories', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.GET_PROJECT_DEVICE_CATEGORY_DEVICE]: { message: 'Failed to get device category devices', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.SITE_UNKNOWN_ERROR]: { message: 'Unknown error from Site Service', status: HttpStatus.INTERNAL_SERVER_ERROR, }, /* Role */ [ErrorCode.GET_ROLES_BY_NAME_FAILED]: { message: 'Failed to get role by name', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.GET_PROJECT_ROLES]: { message: 'Failed to get project roles', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.PERMISSION_VALIDATION_FAILED]: { message: 'Permissions validation failed, dependencies required', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.GET_ROLES_BY_IDS_FAILED]: { message: 'Failed to get roles by ids', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.GET_ROLES_VALIDATION_FAILED]: { message: 'Invalid request provided role name and ids', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.DELETE_ROLE_FAILED]: { message: 'Failed to delete role', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.GET_SYSTEM_ROLES]: { message: 'Failed to get system roles', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.GET_PERMISSION_FAILED]: { message: 'Failed to get permissions', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.GET_PERMISSION_BY_ROLE_IDS_FAILED]: { message: 'Failed to get authorization by id', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.CREATE_ROLE_FAILED]: { message: 'Failed to create role, role name already exist', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.UPDATE_ROLE_FAILED]: { message: 'Failed to update role', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.GET_SYSTEM_ROLES_PERMISSION_REQUEST]: { message: 'Failed to get role permissions', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.PROTECTED_ROLE]: { message: 'Cannot edit or delete project role', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.GET_ACL_BY_ID]: { message: 'Failed to get acls by ids', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.ROLE_UNKNOWN_ERROR]: { message: 'Unknown error from role service', status: HttpStatus.INTERNAL_SERVER_ERROR, }, /* Outbound */ [ErrorCode.SEND_EMAIL]: { message: 'Failed to send an email', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.SEND_SMS]: { message: 'Failed to send an sms', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.SEND_SMS]: { message: 'Failed to send an sms', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.OUTBOUND_UNKNOWN_ERROR]: { message: 'Unknown error from Outbound Service', status: HttpStatus.INTERNAL_SERVER_ERROR, }, /* Billing */ [ErrorCode.GET_INVOICES_BY_PROJECT]: { message: 'Failed to get invoices by project short id', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.GET_INVOICES_BY_ID]: { message: 'Failed to get invoices by id', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.CREATE_INVOICE]: { message: 'Failed to create new invoice for project', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.DELETE_INVOICE]: { message: 'Failed to delete project invoice', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.DOWNLOAD_INVOICE]: { message: 'Failed to download invoice', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.EMAIL_INVOICE]: { message: 'Failed to get invoices for email', status: HttpStatus.BAD_REQUEST, }, }, [ErrorType.SYSTEM]: { /* System */ [ErrorCode.MAP_ACCOUNT_BY_TYPE]: { message: 'Failed to map accounts by type', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.JSON_STRINGIFY_SERVICE_ACCOUNT_KEY]: { message: 'Failed to create service account key json file', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.WRITE_RESPONSE_DATA]: { message: 'Failed to write response data', status: HttpStatus.INTERNAL_SERVER_ERROR, }, [ErrorCode.NO_SERVICE_ACCOUNTS_RECEIVED]: { message: 'No services accounts received from request', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.NO_USERS_RECEIVED]: { message: 'No users received from request', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.NO_AGENTS_RECEIVED]: { message: 'No agents received from request', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.NO_APPS_RECEIVED]: { message: 'No applications received from request', status: HttpStatus.BAD_REQUEST, }, [ErrorCode.NO_AGENT_ASSIGN_TO_SERVICE_ACCOUNT]: { message: 'No Agent assigned to Service Account', status: HttpStatus.UNAUTHORIZED, }, [ErrorCode.LOGUT]: { message: 'Failed to log out', status: HttpStatus.INTERNAL_SERVER_ERROR, }, }, /* Bad Request */ [ErrorType.BAD_REQUEST_VALIDATION]: { [ErrorCode.NO_USER_ACCOUNTS_TO_REMOVE]: { message: 'No User Accounts to remove', status: HttpStatus.BAD_REQUEST, }, }, }; static getErrorCode(type: ErrorType, code: number): ErrorCodeDetails { if (this.ErrorCodeMap[type]) { if (this.ErrorCodeMap[type][code]) { return this.ErrorCodeMap[type][code]; } AppLogger.warn(`An unhandled error code received - ${code} on type - ${type}`, this.TAG); return this.ErrorCodeMap[ErrorType.UNKNOWN][ErrorCode.UNKNOWN]; } AppLogger.warn(`An unhandled error type received - ${type}`, this.TAG); return this.ErrorCodeMap[ErrorType.UNKNOWN][ErrorCode.UNKNOWN]; } }