( message: string, fallbackTitle = '操作失败', status = 500, suggestion?: string )
| 78 | } |
| 79 | |
| 80 | function legacyMessageToError( |
| 81 | message: string, |
| 82 | fallbackTitle = '操作失败', |
| 83 | status = 500, |
| 84 | suggestion?: string |
| 85 | ): AppError { |
| 86 | const clean = message || '发生未知错误' |
| 87 | const firstLine = clean.split('\n').map(line => line.trim()).find(Boolean) || fallbackTitle |
| 88 | |
| 89 | return { |
| 90 | type: `https://redink.app/errors/${inferCode(clean).toLowerCase().replace(/_/g, '-')}`, |
| 91 | code: inferCode(clean), |
| 92 | title: inferTitle(clean, fallbackTitle), |
| 93 | detail: firstLine, |
| 94 | suggestion: suggestion || inferSuggestion(clean), |
| 95 | status: status || 500, |
| 96 | retryable: inferRetryable(clean), |
| 97 | diagnostics: { |
| 98 | raw: clean |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | function inferCode(message: string): string { |
| 104 | const text = message.toLowerCase() |
no test coverage detected