http-exception

MOVED to https://github.com/belgattitude/httpx/tree/main/packages/exception#readme

MIT License

Downloads
1.7K
Stars
2
Committers
3

Bot releases are hidden (Show)

http-exception - @belgattitude/[email protected] Latest Release

Published by belgattitude almost 2 years ago

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.

http-exception - @belgattitude/[email protected]

Published by belgattitude almost 2 years ago

Minor Changes

http-exception - @belgattitude/[email protected]

Published by belgattitude about 2 years ago

Patch Changes

http-exception - @belgattitude/[email protected]

Published by belgattitude about 2 years ago

Patch Changes

http-exception - @belgattitude/[email protected]

Published by belgattitude about 2 years ago

Patch Changes

http-exception - @belgattitude/[email protected]

Published by belgattitude about 2 years ago

Patch Changes

http-exception - @belgattitude/[email protected]

Published by belgattitude about 2 years ago

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

http-exception - @belgattitude/[email protected]

Published by belgattitude about 2 years ago

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

http-exception - @belgattitude/[email protected]

Published by belgattitude about 2 years ago

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
    
http-exception - @belgattitude/[email protected]

Published by belgattitude about 2 years ago

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

http-exception - @belgattitude/[email protected]

Published by belgattitude about 2 years ago

Patch Changes

http-exception - @belgattitude/[email protected]

Published by belgattitude about 2 years ago

Major Changes

Patch Changes

http-exception - @belgattitude/[email protected]

Published by belgattitude about 2 years ago

Patch Changes

http-exception - @belgattitude/[email protected]

Published by belgattitude about 2 years ago

Patch Changes

http-exception - @belgattitude/[email protected]

Published by belgattitude about 2 years ago

Patch Changes

http-exception - @belgattitude/[email protected]

Published by belgattitude about 2 years ago

Patch Changes

http-exception - @belgattitude/[email protected]

Published by belgattitude about 2 years ago

Patch Changes

http-exception - @belgattitude/[email protected]

Published by belgattitude about 2 years ago

Patch Changes

http-exception - @belgattitude/[email protected]

Published by belgattitude about 2 years ago

Patch Changes

http-exception - @belgattitude/[email protected]

Published by belgattitude about 2 years ago

Patch Changes