Skip to content

Commit

Permalink
Merge pull request #54 from belgattitude/changeset-release/main
Browse files Browse the repository at this point in the history
Version Packages
  • Loading branch information
belgattitude authored Sep 21, 2022
2 parents 9dce653 + ede57e1 commit d9f24e6
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 45 deletions.
43 changes: 0 additions & 43 deletions .changeset/friendly-ducks-fry.md

This file was deleted.

7 changes: 7 additions & 0 deletions examples/nextjs-app/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @examples/nextjs-app

## 0.1.13

### Patch Changes

- Updated dependencies [[`67be0fb`](https://github.com/belgattitude/http-exception/commit/67be0fbbb1acafa2c12a8c5a45b30f8b79ad3c4c)]:
- @belgattitude/http-exception@1.1.0

## 0.1.12

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion examples/nextjs-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@examples/nextjs-esm",
"version": "0.1.12",
"version": "0.1.13",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
43 changes: 43 additions & 0 deletions packages/http-exception/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,48 @@
# @belgattitude/http-exception

## 1.1.0

### Minor Changes

- [#33](https://github.com/belgattitude/http-exception/pull/33) [`67be0fb`](https://github.com/belgattitude/http-exception/commit/67be0fbbb1acafa2c12a8c5a45b30f8b79ad3c4c) Thanks [@belgattitude](https://github.com/belgattitude)! - Add HttpException json serializer.

Two new methods `fromJson` and `toJson` exported from `@belgattitude/http-exception/serializer`.

HttpException can be serialized to json and vice-versa. It can be useful in ssr frameworks such as
[nextjs](https://nextjs.org/) whenever a server error should be shared within the browser context (see also
the excellent [superjson](https://github.com/blitz-js/superjson#recipes)).

Serialization supports the [Error.cause](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause)
but totally ignores it the runtime (node or browser) does not support it (or without polyfills).

Additionally, you can pass any native errors (`Error`, `EvalError`, `RangeError`, `ReferenceError`, `SyntaxError`, `TypeError`, `URIError`)
as well as a custom one (the later will be transformed to the base type Error). That was necessary to support the cause param.

| Method |
| ------------------------------------------------------------------- |
| **toJson**(HttpException | NativeError | Error): string |
| **fromJson**(string): HttpException | NativeError | Error |

```typescript
import {
HttpForbidden,
HttpUnavailableForLegalReasons,
} from '@belgattitude/http-exception';
import { fromJson, toJson } from '@belgattitude/http-exception/serializer';

const e = new HttpForbidden({
url: 'https://www.cool.me',
/*
cause: new HttpUnavailableForLegalReasons({
cause: new Error('example with cause')
}),
*/
});

const json = toJson(e);
const exception = fromJson(json); // e === exception
```

## 1.0.2

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/http-exception/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@belgattitude/http-exception",
"version": "1.0.2",
"version": "1.1.0",
"license": "MIT",
"homepage": "https://github.com/belgattitude/http-exception",
"repository": {
Expand Down

0 comments on commit d9f24e6

Please sign in to comment.