MOVED to https://github.com/belgattitude/httpx/tree/main/packages/exception#readme
MIT License
Bot releases are visible (Hide)
Published by belgattitude almost 2 years ago
#204 c128653
Thanks @belgattitude! - Package moved to @httpx/exception.
⚠️ Version 1.5.0 will be the last one ! We've moved to https://github.com/belgattitude/httpx ⚠️
No breaking changes, just update from
@belgattitude/http-exception
to@httpx/exception
.The change to
httpx
namespace makes it shorter, allow more
packages to be grouped and eventually will be managed inside a github org.
Published by belgattitude almost 2 years ago
57574ed
Thanks @belgattitude! - Upgrapde to rollup v3Published by belgattitude about 2 years ago
2bea0d6
Thanks @belgattitude! - Bundle with rollup v3.0.0Published by belgattitude about 2 years ago
5b964fd
Thanks @belgattitude! - Disable minification to allow patching (patch-package...)Published by belgattitude about 2 years ago
9498cb2
Thanks @belgattitude! - Remove hardcoded string in supportsCause functionPublished by belgattitude about 2 years ago
a8fbdd2
Thanks @belgattitude! - Fix potential issue with cause that could be undefinedPublished by belgattitude about 2 years ago
#75 89d2dd8
Thanks @belgattitude! - Added method
, code
and errorId
params.
Name | Type | Description |
---|---|---|
url | string? |
url on which the error happened |
method | string? |
http method used to load the url |
code | string? |
Custom code (ie: 'AbortError', 'E-1234'...) |
errorId | string? |
Unique error identifier (ie: uuid, nanoid...) |
const err = new HttpRequestTimeout({
url: 'https://api.dev/user/belgattitude',
method: 'GET',
code: 'NETWORK_FAILURE',
errorId: nanoid(), // can be shared by frontend/backend
});
console.log(err.url, err.method, err.code, err.errorId);
f3c423f
Thanks @belgattitude! - Improved documenation and website livePublished by belgattitude about 2 years ago
#67 7208e7b
Thanks @belgattitude! - Export convertToSerializable and createFromSerializable
import {
convertToSerializable,
createFromSerializable,
} from '@belgattitude/http-exception/serializer';
const serializableObject = convertToSerializable(new HttpForbidden());
const exception = createFromSerializable(serializableObject);
bddd84a
Thanks @belgattitude! - Initial documentation and updated examplesPublished by belgattitude about 2 years ago
#33 67be0fb
Thanks @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 whenever a server error should be shared within the browser context (see also
the excellent superjson).
Serialization supports the 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 |
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
Published by belgattitude about 2 years ago
#51 421b36d
Thanks @belgattitude! - Fix Error.cause
on node < 16.9 and browsers that don't support for it.
The strategy used can be summarized as:
If the browser or the node runtime does not support Error.cause parameter in the
constructor, it will simply be discarded.
ie:const err = new HttpNotFound({cause: new Error()}); console.log(err.cause) -> undefined if no support console.log(err.cause) -> Error cause if supported
To enable older browser or previous node versions, there's 2 polyfills that should
do the job
Published by belgattitude about 2 years ago
d1ed899
Thanks @belgattitude! - Support for older browser (class / spread transform)Published by belgattitude about 2 years ago
662db5f
Thanks @belgattitude! - Coverage at 100% and last fixes#28 c76dd69
Thanks @belgattitude! - Squeeze out 450 bytes for full import
#25 c153ff8
Thanks @belgattitude! - Improve build
Published by belgattitude about 2 years ago
c76dd69
Thanks @belgattitude! - Squeeze out 450 bytes for full importPublished by belgattitude about 2 years ago
c153ff8
Thanks @belgattitude! - Improve buildPublished by belgattitude about 2 years ago
#18 6a81535
Thanks @belgattitude! - Improve tree-shaking
#20 633b1e0
Thanks @belgattitude! - Improve tree-shaking commonjs
Published by belgattitude about 2 years ago
633b1e0
Thanks @belgattitude! - Improve tree-shaking commonjsPublished by belgattitude about 2 years ago
6a81535
Thanks @belgattitude! - Improve tree-shakingPublished by belgattitude about 2 years ago
cdf3333
Thanks @belgattitude! - Add sourcemaps to published distPublished by belgattitude about 2 years ago
3fe82d8
Thanks @belgattitude! - Internal package in cjs to help dual packagingPublished by belgattitude about 2 years ago
76f7fea
Thanks @belgattitude! - Remove browser field