Skip to content

Latest commit

 

History

History
760 lines (479 loc) · 33.9 KB

CHANGELOG.md

File metadata and controls

760 lines (479 loc) · 33.9 KB

@httpx/exception

3.0.6

Patch Changes

3.0.5

Patch Changes

3.0.4

Patch Changes

3.0.3

Patch Changes

3.0.2

Patch Changes

3.0.1

Patch Changes

3.0.0

Major Changes

  • #873 62332de Thanks @belgattitude! - Stack traces won't be serialized anymore by default as they might contain sensitive information in production.

    For development or logging, it's possible to opt-in stack serialization selectively in convertToSerializable, createFromSerializable, toJson and fromJson functions thanks to the SerializerParams.includeStack param.

    import { fromJson, toJson } from "@httpx/exception";
    
    const json = toJson(new HttpException(500), {
      includeStack: process.env.NODE_ENV === "development",
    });
    
    const e = fromJson(json, {
      includeStack: process.env.NODE_ENV === "development",
    });
  • #865 a1b3c9f Thanks @belgattitude! - Remove deprecated errors param from HttpBadRequest, use issues in HttpUnprocessableEntity instead

  • #865 a1b3c9f Thanks @belgattitude! - Remove deprecated errors params from HttpUnprocessableEntity, use issues instead

  • #865 a1b3c9f Thanks @belgattitude! - Remove deprecated type HttpStatusCode, use HttpErrorStatusCode instead.

  • #865 a1b3c9f Thanks @belgattitude! - Remove deprecated type ValidationError, use HttpValidationIssue instead.

Minor Changes

Patch Changes

2.6.4

Patch Changes

2.6.3

Patch Changes

2.6.2

Patch Changes

2.6.1

Patch Changes

2.6.0

Minor Changes

  • #815 77cd15b Thanks @belgattitude! - Deprecate the type HttpStatusCode, use HttpErrorStatusCode instead

    HttpErrorStatusCode is less ambiguous ad HttpStatusCode could be understood as HttpStatusCode could represent all http statuses. The type is exported but there's very few chances an regular user would be impacted.

  • #815 77cd15b Thanks @belgattitude! - Add new types: HttpErrorStatusCode and HttpErrorStatusCodeOrNumber

    Improves the typescript experience by allowing typescript to suggest assigned status codes in createException and HttpException, HttpClientException, HttpServerException constructors. Arbitray numbers can still be used.

  • #815 77cd15b Thanks @belgattitude! - Add new typeguards: isErrorWithErrorStatusCode and isObjectWithErrorStatusCode

    Those typeguards can be used in specific circumstances when an originating error has a statusCode field which indicates by convention the preferred status to send.

    import {
      isErrorWithErrorStatusCode,
      createHttpException,
    } from "@httpx/exception";
    
    try {
      throw new (class extends Error {
        statusCode = 400;
      })();
    } catch (e) {
      if (isErrorWithErrorStatusCode(e)) {
        throw createException(e.statusCode, "Something wrong happened");
      }
    }
    const noSuchUser = {
      statusCode: 404,
    } satisfies ObjectWithStatusCode;
    
    class NoSuchItem extends DomainError implements ObjectWithStatusCode {
      statusCode: 404;
    }
    
    if (isObjectWithErrorStatusCode(noSuchUser)) {
      throw createException(e.statusCode, "Nothing");
    }

2.5.7

Patch Changes

2.5.6

Patch Changes

2.5.5

Patch Changes

2.5.4

Patch Changes

2.5.3

Patch Changes

2.5.2

Patch Changes

2.5.1

Patch Changes

2.5.0

Minor Changes

  • #675 a6a63e1 Thanks @belgattitude! - Add support for HttpUnprocessableEntity.issues in serializer.

    import { fromJson, toJson } from "@httpx/exception/serializer";
    
    const e422 = new HttpUnprocessableEntity({
      message: "Validation failed",
      issues: [
        {
          message: "Invalid address",
          path: ["addresses", 0, "line1"],
          code: "empty_string",
        },
      ],
    });
    
    const json = toJson(e422);
    const js = fromJson(json);
    
    expect((js as HttpUnprocessableEntity).issues).toStrictEqual(e422.issues);
    expect(js).toStrictEqual(e422);

Patch Changes

  • #675 a6a63e1 Thanks @belgattitude! - Fix createHttpException that wasn't allowing issues on HttpUnprocessableEntity

    const e422 = createHttpException(422, {
      message: "Validation failed",
      issues: [
        {
          message: "Invalid address",
          path: ["addresses", 0, "line1"],
          code: "empty_string",
        },
      ],
    });

2.4.0

Minor Changes

  • #672 9d1d248 Thanks @belgattitude! - Reduce bundle size by using class names rather than strings

    Importing all exceptions (excluding utilities, typeguards...) now top at 1Kb

    Example based on ESM (min+gzip)

    Scenario Size
    one exception ~ 450b
    all exceptions < 1kb
    everything (typeguards,...) 1.7kb

2.3.0

Minor Changes

  • #667 6872abb Thanks @belgattitude! - Minimum node version is 18.12. Move to es2022.

  • #667 6872abb Thanks @belgattitude! - Reduce drastically bundle size (use es2022)

    Importing a single exception starts at 377 bytes, subsequent ones will add less than 50 bytes in average. Importing all exceptions (excluding typeguards...) will top at 1400 bytes.

    Code should be faster too.

    PS: if you use exceptions outside of nodejs and need to support legacy browsers a lot of frameworks allows to transpile modules (ie nextjs).

    ✔ Adding to empty webpack project
    
      ESM (import everything *)
      Package size is 395 B less than limit
      Size limit: 2.46 kB
      Size:       2.06 kB with all dependencies, minified and gzipped
    
      ESM (only HttpNotFound exception)
      Package size is 965 B less than limit
      Size limit: 1.42 kB
      Size:       450 B   with all dependencies, minified and gzipped
    
      ESM (two exceptions: HttpNotFound + HttpInternalServerError)
      Package size is 935 B less than limit
      Size limit: 1.44 kB
      Size:       505 B   with all dependencies, minified and gzipped
    
      ESM (only isHttpException)
      Package size is 1.03 kB less than limit
      Size limit: 1.41 kB
      Size:       377 B   with all dependencies, minified and gzipped
    
      ESM (only createHttpException)
      Package size is 571 B less than limit
      Size limit: 2 kB
      Size:       1.43 kB with all dependencies, minified and gzipped
    
      ESM ({ toJson })
      Package size is 1.11 kB less than limit
      Size limit: 1.89 kB
      Size:       779 B   with all dependencies, minified and gzipped
    
      ESM ({ fromJson })
      Package size is 607 B less than limit
      Size limit: 2.5 kB
      Size:       1.89 kB with all dependencies, minified and gzipped
    
      CJS (require everything *)
      Package size is 416 B less than limit
      Size limit: 3.05 kB
      Size:       2.63 kB with all dependencies, minified and gzipped
    
      CJS (only isHttpException)
      Package size is 598 B less than limit
      Size limit: 2.5 kB
      Size:       1.9 kB with all dependencies, minified and gzipped
    
    

2.2.0

Minor Changes

  • 81311de Thanks @belgattitude! - Deprecate ValidationError type in favour of HttpValidationIssue

    // @deprecated errors
    // const errors: ValidationError[] = [
    
    // becomes
    const issues: HttpValidationIssue[] = [
      {
        message: "Invalid email",
        path: "email",
        code: "invalid_email",
      },
      {
        message: "Invalid address",
        path: ["addresses", 0, "line1"],
        code: "empty_string",
      },
    ];
    
    const e422 = new HttpUnprocessableEntity({
      // @deprecated name
      // errors: errors,
    
      // becomes issues
      issues: [],
    });

2.1.1

Patch Changes

2.1.0

Minor Changes

2.0.0

Major Changes

  • #512 58ea021 Thanks @belgattitude! - Minimum to node 16.12 / es2018 and modern browsers (>1%)

    Possibly a breaking change for some users relying on older browsers.

Minor Changes

Patch Changes

1.8.3

Patch Changes

1.8.2

Patch Changes

1.8.1

Patch Changes

1.8.0

Minor Changes

  • #402 6b945d3 Thanks @belgattitude! - Add field error validation support for 422 HttpUnprocessableEntity

    Example:

    import { HttpUnprocessableEntity } from "@httpx/exception";
    
    const e422 = new HttpUnprocessableEntity({
      errors: [
        {
          message: "Invalid email",
          path: "email",
          code: "invalid_email",
        },
        {
          message: "Invalid address",
          path: ["addresses", 0, "line1"],
          code: "empty_string",
        },
      ],
    });
    
    console.log(e422.errors);

Patch Changes

1.7.2

Patch Changes

1.7.1

Patch Changes

1.7.0

Minor Changes

  • #31 167c216 Thanks @belgattitude! - Support ValidationError in HttpBadRequest

    In some circumstances you might find useful to append the validation errors to HttpBadRequest. Here's a quick example:

    const e400 = new HttpBadRequest({
      errors: [
        {
          message: "Invalid email",
          path: "email",
          code: "invalid_email",
        },
        {
          message: "Invalid address",
          path: ["addresses", 0, "line1"],
          code: "empty_string",
        },
      ],
    });
    console.log(e400.errors);

1.6.2

Patch Changes

1.6.1

Patch Changes

1.6.0

Minor Changes

1.5.0

Minor Changes

  • #5 b51c863 Thanks @belgattitude! - Rename package to @httpx/exception

    The @belgattitude/http-exception package have been renamed to @httpx/exception.

1.4.0

Before v1.5.0 the @httpx/exception package was named `@belgattitude/http-exception and lived in https://github.com/begattitude/http-exception repository.

Minor Changes

1.3.4

Patch Changes

1.3.3

Patch Changes

1.3.2

Patch Changes

1.3.1

Patch Changes

1.3.0

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/server
    });
    console.log(err.url, err.method, err.code, err.errorId);

Patch Changes

1.2.0

Minor Changes

  • #67 7208e7b Thanks @belgattitude! - Export convertToSerializable and createFromSerializable

    import {
      convertToSerializable,
      createFromSerializable,
    } from "@httpx/exception/serializer";
    
    const serializableObject = convertToSerializable(new HttpForbidden());
    const exception = createFromSerializable(serializableObject);

Patch Changes

1.1.0

Minor Changes

  • #33 67be0fb Thanks @belgattitude! - Add HttpException json serializer.

    Two new methods fromJson and toJson exported from @httpx/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 "@httpx/exception";
    import { fromJson, toJson } from "@httpx/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

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

1.0.1

Patch Changes

1.0.0

Major Changes

Patch Changes

0.1.10-canary.1

Patch Changes

0.1.10-canary.0

Patch Changes

0.1.9

Patch Changes

0.1.9-canary.1

Patch Changes

0.1.9-canary.0

Patch Changes

0.1.8

Patch Changes

0.1.7

Patch Changes

0.1.6

Patch Changes

0.1.5

Patch Changes

0.1.4

Patch Changes

0.1.3

Patch Changes

0.1.2

Patch Changes

0.1.1

Patch Changes