mirror of
https://github.com/Jeuners/ECC.git
synced 2026-09-09 15:02:30 +02:00
docs: align TypeScript error handling examples
This commit is contained in:
parent
327c2e97d8
commit
b0a6847007
1 changed files with 8 additions and 2 deletions
|
|
@ -72,7 +72,7 @@ function getErrorMessage(error: unknown): string {
|
|||
return error.message
|
||||
}
|
||||
|
||||
return 'Unknown error'
|
||||
return 'Unexpected error'
|
||||
}
|
||||
```
|
||||
|
||||
|
|
@ -158,12 +158,18 @@ function getErrorMessage(error: unknown): string {
|
|||
return 'Unexpected error'
|
||||
}
|
||||
|
||||
const logger = {
|
||||
error: (message: string, error: unknown) => {
|
||||
// Replace with your production logger (for example, pino or winston).
|
||||
}
|
||||
}
|
||||
|
||||
async function loadUser(userId: string): Promise<User> {
|
||||
try {
|
||||
const result = await riskyOperation(userId)
|
||||
return result
|
||||
} catch (error: unknown) {
|
||||
console.error('Operation failed:', error)
|
||||
logger.error('Operation failed', error)
|
||||
throw new Error(getErrorMessage(error))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue