Skip to content

Commit 2c598f1

Browse files
committed
Document error.beautiful()
1 parent af33d2a commit 2c598f1

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

β€ŽREADME.mdβ€Ž

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ Error handler for CLI applications.
1414
# Features
1515

1616
- πŸ–οΈ Pretty [colors](#%EF%B8%8F-colors), [icons](#-icon) and [header](#-header)
17-
- πŸ’£ [Error class-specific](#-classes) handling
17+
- πŸ’£ [Error class-specific](#-classes) and [custom](#custom-serialization)
18+
handling
1819
- πŸš’ [Graceful exit](#-timeout)
1920
- ⛑️ [Normalize](https://github.com/ehmicky/normalize-exception) invalid errors
2021
- πŸ”• Log verbosity: [message](#-silent), [stack](#-stack),
@@ -193,6 +194,24 @@ Specify [different options per error class](#error-class-specific). The object:
193194
or `"default"` (used if no `error.name` matches)
194195
- Values are [options](#options) objects
195196

197+
## Custom serialization
198+
199+
The output can be transformed/mapped by defining an `error.beautiful(output)`
200+
method returning a string.
201+
202+
<!-- eslint-disable fp/no-class -->
203+
204+
```js
205+
class ExampleError extends Error {
206+
beautiful(output) {
207+
return output.replaceAll('secret', '***')
208+
}
209+
}
210+
211+
const error = new ExampleError('Unknown value: secret')
212+
handleCliError(error) // 'Unknown value: ***'
213+
```
214+
196215
# Related projects
197216

198217
- [`modern-errors`](https://github.com/ehmicky/modern-errors): Handle errors in

0 commit comments

Comments
Β (0)