-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add details mapping helpers to HTTPError
- Loading branch information
1 parent
e63b24d
commit 818bf6a
Showing
2 changed files
with
75 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--- | ||
'@kurrent-ui/utils': minor | ||
--- | ||
|
||
`HTTPError` has two new helper methods for modifying it's problem details | ||
|
||
### `HTTPError.mapProblemDetails` | ||
|
||
Allows you to create a new HTTPError that will call the passed mapping function on it's details. | ||
|
||
Example usage: | ||
|
||
```ts | ||
try { | ||
await callAPI(); | ||
} catch (e) { | ||
if (HTTPError.isHTTPError(error)) { | ||
throw error.mapProblemDetails((details) => ({ | ||
...details, | ||
title: "Its's okay..", | ||
})); | ||
} | ||
|
||
throw error; | ||
} | ||
``` | ||
|
||
### `HTTPError.mapFieldKeys` | ||
|
||
Allows you to create a new HTTPError that will call the passed mapping function on it's detail's field keys. | ||
|
||
Example usage: | ||
|
||
```ts | ||
try { | ||
await callAPI(); | ||
} catch (e) { | ||
if (HTTPError.isHTTPError(error)) { | ||
throw throw error.mapFieldKeys((key) => | ||
key.replace(/^chicken/, 'turkey'), | ||
); | ||
} | ||
|
||
throw error; | ||
} | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters