Skip to content

Releases: belgattitude/http-exception

@belgattitude/http-exception@1.5.0

22 Nov 09:21
4398b05
Compare
Choose a tag to compare

Minor Changes

  • #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.

@belgattitude/http-exception@1.4.0

21 Oct 01:13
86a3a6c
Compare
Choose a tag to compare

Minor Changes

@belgattitude/http-exception@1.3.4

12 Oct 09:35
e02bef7
Compare
Choose a tag to compare

Patch Changes

@belgattitude/http-exception@1.3.3

04 Oct 21:07
814f8b8
Compare
Choose a tag to compare

Patch Changes

@belgattitude/http-exception@1.3.2

03 Oct 10:33
37334fd
Compare
Choose a tag to compare

Patch Changes

@belgattitude/http-exception@1.3.1

30 Sep 19:15
967395b
Compare
Choose a tag to compare

Patch Changes

@belgattitude/http-exception@1.3.0

27 Sep 13:09
437dbc3
Compare
Choose a tag to compare

Minor Changes

  • #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);

Patch Changes

@belgattitude/http-exception@1.2.0

24 Sep 21:16
c473447
Compare
Choose a tag to compare

Minor Changes

  • #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);

Patch Changes

@belgattitude/http-exception@1.1.0

21 Sep 18:07
d9f24e6
Compare
Choose a tag to compare

Minor Changes

  • #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

@belgattitude/http-exception@1.0.2

21 Sep 00:38
0ad4479
Compare
Choose a tag to compare

Patch Changes

  • #51 421b36d Thanks @belgattitude! - Fix Error.cause on node < 16.9 and browsers that don't support for it.

    • Browser currently 89% support: caniuse#error.cause - (89% supports it as of sept 2022)
    • Node from 16.9.0 as per mdn.

    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