MCPcopy Index your code
hub / github.com/codebymitch/TitanBot / inferErrorType

Function inferErrorType

src/utils/serviceErrorBoundary.js:14–45  ·  view source on GitHub ↗
(error, fallbackType = ErrorTypes.UNKNOWN)

Source from the content-addressed store, hash-verified

12}
13
14function inferErrorType(error, fallbackType = ErrorTypes.UNKNOWN) {
15 const message = error?.message?.toLowerCase?.() || '';
16 const code = error?.code;
17
18 if (typeof code === 'string') {
19 if (code.includes('PERMISSION') || code.includes('FORBIDDEN')) {
20 return ErrorTypes.PERMISSION;
21 }
22
23 if (code.includes('VALIDATION') || code.includes('INVALID')) {
24 return ErrorTypes.VALIDATION;
25 }
26
27 if (code.includes('DB') || code.includes('SQL') || code.includes('POSTGRES')) {
28 return ErrorTypes.DATABASE;
29 }
30 }
31
32 if (message.includes('permission') || message.includes('forbidden')) {
33 return ErrorTypes.PERMISSION;
34 }
35
36 if (message.includes('database') || message.includes('sql') || message.includes('connection') || message.includes('timeout')) {
37 return ErrorTypes.DATABASE;
38 }
39
40 if (message.includes('validation') || message.includes('invalid') || message.includes('required')) {
41 return ErrorTypes.VALIDATION;
42 }
43
44 return fallbackType;
45}
46
47export function ensureTypedServiceError(error, options = {}) {
48 if (error instanceof TitanBotError) {

Callers 1

ensureTypedServiceErrorFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected