(error, options = {})
| 45 | } |
| 46 | |
| 47 | export function ensureTypedServiceError(error, options = {}) { |
| 48 | if (error instanceof TitanBotError) { |
| 49 | return error; |
| 50 | } |
| 51 | |
| 52 | const context = normalizeBoundaryContext(options.context); |
| 53 | const fallbackType = options.type || ErrorTypes.UNKNOWN; |
| 54 | const type = inferErrorType(error, fallbackType); |
| 55 | const service = options.service || 'unknown_service'; |
| 56 | const operation = options.operation || 'unknown_operation'; |
| 57 | const errorCode = resolveErrorCode({ |
| 58 | error, |
| 59 | errorType: type, |
| 60 | context: { |
| 61 | errorCode: options.errorCode || `${service}.${operation}.failed` |
| 62 | } |
| 63 | }); |
| 64 | const errorMetadata = getErrorMetadata(errorCode); |
| 65 | const message = options.message || `${service}.${operation} failed`; |
| 66 | const userMessage = options.userMessage || 'Something went wrong while processing your request.'; |
| 67 | |
| 68 | return createError(message, type, userMessage, { |
| 69 | ...context, |
| 70 | service, |
| 71 | operation, |
| 72 | errorCode, |
| 73 | remediationHint: errorMetadata.remediation, |
| 74 | severity: errorMetadata.severity, |
| 75 | retryable: errorMetadata.retryable, |
| 76 | originalErrorMessage: error?.message || String(error), |
| 77 | originalErrorName: error?.name || 'Error', |
| 78 | expected: false |
| 79 | }); |
| 80 | } |
| 81 | |
| 82 | export function wrapServiceBoundary(fn, options = {}) { |
| 83 | return function wrappedServiceBoundary(...args) { |
no test coverage detected