UNPKG

asksuite-core

Version:
34 lines (31 loc) 1.07 kB
class ErrorHandlerService { constructor() { this.acessorErrorTypes = { serviceUnreachable: 'SERVICE_UNREACHABLE', serviceError: 'SERVICE_ERROR', serviceTimeoutError: 'SERVICE_TIMEOUT_ERROR', notMappedError: 'NOT_MAPPED_ERROR', }; } accessorErrorHandler(error) { const errorData = { errorReason: this.acessorErrorTypes.notMappedError, errorCode: error.code, message: error.message, requestId: error.requestId, }; if (error) { if (['UnknownEndpoint', 'ECONNREFUSED'].includes(error.code)) { errorData.errorReason = this.acessorErrorTypes.serviceUnreachable; } if (['ETIMEDOUT', 'ESOCKETTIMEDOUT'].includes(error.code)) { errorData.errorReason = this.acessorErrorTypes.serviceTimeoutError; } if (Number.isInteger(error.code) || ['UnknownError'].includes(error.code)) { errorData.errorReason = this.acessorErrorTypes.serviceError; } } return errorData; } } module.exports = { ErrorHandlerService: new ErrorHandlerService() };