File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
You canβt perform that action at this time.
0 commit comments