- #1546
bdf9e19
Thanks @belgattitude! - Ensure CI tests on Clouflare workers and latest chrome (playwright)
- #1418
366520a
Thanks @belgattitude! - Internal refactor based on linter updates
- #1375
36733f0
Thanks @belgattitude! - Support typescript "exactOptionalPropertyTypes". See typescript blog
-
#1369
b39a71c
Thanks @belgattitude! - Add git url prefix in package.json -
#1369
b39a71c
Thanks @belgattitude! - Remove unecessary default condition from exports -
#1369
b39a71c
Thanks @belgattitude! - Add publint after arethetypeswrong checks
- #1335
f6d0479
Thanks @belgattitude! - Minor internal fix to HttpUnprocessableEntity
- #1154
6a52be7
Thanks @belgattitude! - Rebuild using esbuild 0.20.2
- #990
a006c93
Thanks @belgattitude! - Minor refactors and readme updates
- #971
ab3767f
Thanks @belgattitude! - Fix classname mangling
- #916
8ab0e1a
Thanks @belgattitude! - Fix README documentation regarding helpers
28687e1
Thanks @belgattitude! - Release with npm provenance
- #877
e329bcd
Thanks @belgattitude! - Add npm provenance to releases
-
#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
andfromJson
functions thanks to theSerializerParams.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 deprecatederrors
param fromHttpBadRequest
, useissues
inHttpUnprocessableEntity
instead -
#865
a1b3c9f
Thanks @belgattitude! - Remove deprecatederrors
params fromHttpUnprocessableEntity
, useissues
instead -
#865
a1b3c9f
Thanks @belgattitude! - Remove deprecated typeHttpStatusCode
, useHttpErrorStatusCode
instead. -
#865
a1b3c9f
Thanks @belgattitude! - Remove deprecated typeValidationError
, useHttpValidationIssue
instead.
-
#865
a1b3c9f
Thanks @belgattitude! - Reduce typical usage bundle size to 400b-660b range -
#873
62332de
Thanks @belgattitude! - AddSerializerParams.includeStack
totoJson
andfromJson
serialization functions. -
#873
62332de
Thanks @belgattitude! - AddSerializerParams.includeStack
toconvertToSerializable
andcreateFromSerializable
serialization functions.
-
#870
5ea92c1
Thanks @belgattitude! - Fix cause support in SerializerError on env that doesn't support Error.cause -
#875
b6e2941
Thanks @belgattitude! - Update to rollup 4.9.4 -
#869
c65e11a
Thanks @belgattitude! - Fix missing export of isObjectWithErrorStatusCode
- #858
76fd8dc
Thanks @belgattitude! - Release with no changes
-
b418b0b
Thanks @belgattitude! - Release unreleased patches -
#854
f01defc
Thanks @belgattitude! - Add doc for nested errors
- #850
e17f083
Thanks @belgattitude! - Fix potential cyclic imports
-
#834
9d4dd98
Thanks @belgattitude! - Add missing doc for nested errors -
#832
321957a
Thanks @belgattitude! - esbuild updated to 0.19.11 to fix a potential typeScript-specific class transform edge case
-
#815
77cd15b
Thanks @belgattitude! - Deprecate the typeHttpStatusCode
, useHttpErrorStatusCode
insteadHttpErrorStatusCode 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 HttpErrorStatusCodeOrNumberImproves the typescript experience by allowing typescript to suggest assigned status codes in
createException
andHttpException
,HttpClientException
,HttpServerException
constructors. Arbitray numbers can still be used. -
#815
77cd15b
Thanks @belgattitude! - Add new typeguards: isErrorWithErrorStatusCode and isObjectWithErrorStatusCodeThose 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"); }
- #788
b004243
Thanks @belgattitude! - Add toc in readme
- #787
39ec1d5
Thanks @belgattitude! - Fix README doc links
- #781
4e2b795
Thanks @belgattitude! - Ensure compat for Chrome 96+, Firefox 90+, Edge 91+, Safari 15+ and Opera 77+
- #778
d76a2f9
Thanks @belgattitude! - Reduce bundle size of createException (-20b)
- #724
8d02a2a
Thanks @belgattitude! - Optimize code thanks to eslint unicorn plugin
- #719
bae6ce0
Thanks @belgattitude! - Upgrade tsup to 7.3 and build with esbuild 0.19.3
- #677
92343d2
Thanks @belgattitude! - Add tupleson tests and improve docs
-
#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);
-
#675
a6a63e1
Thanks @belgattitude! - Fix createHttpException that wasn't allowing issues on HttpUnprocessableEntityconst e422 = createHttpException(422, { message: "Validation failed", issues: [ { message: "Invalid address", path: ["addresses", 0, "line1"], code: "empty_string", }, ], });
-
#672
9d1d248
Thanks @belgattitude! - Reduce bundle size by using class names rather than stringsImporting 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
-
#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
-
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: [], });
- #589
6eab016
Thanks @belgattitude! - Fix serializer type export for older projects
- #532
cfe1808
Thanks @belgattitude! - Lint with typescript/eslint v6 strict
-
#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.
- #512
58ea021
Thanks @belgattitude! - Reduce global file size by transpiling for node 16 and modern browsers.
- #512
58ea021
Thanks @belgattitude! - Fix type exports in some circumstances (masquerading as esm)
- #482
5337e61
Thanks @belgattitude! - Improve typecheck strictness
-
#467
99d6881
Thanks @belgattitude! - Add syncpack to align package.json fields -
#465
245ed6b
Thanks @belgattitude! - Dev dependencies updated to latest
42cdf63
Thanks @belgattitude! - Minor perf by extracting regexp into an hoisted var
-
#402
6b945d3
Thanks @belgattitude! - Add field error validation support for 422 HttpUnprocessableEntityExample:
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);
- #404
f4c2780
Thanks @belgattitude! - Fix cyclic type import and use latest rollup to build
- #309
67321bc
Thanks @belgattitude! - Fix missing serializer export for commonjs (esm worked)
- #143
7ccae63
Thanks @belgattitude! - No changes, just the build with latest rollup/babel
-
#31
167c216
Thanks @belgattitude! - Support ValidationError in HttpBadRequestIn 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);
- #28
3ddb181
Thanks @belgattitude! - Increase legacy browsers usage (+ include latest babel upstream fixes)
- #14
be9dd3f
Thanks @belgattitude! - Missing npm description field
- #10
6f94a9f
Thanks @belgattitude! - Fix release
-
#5
b51c863
Thanks @belgattitude! - Rename package to @httpx/exceptionThe
@belgattitude/http-exception
package have been renamed to@httpx/exception
.
Before v1.5.0 the
@httpx/exception
package was named `@belgattitude/http-exception and lived in https://github.com/begattitude/http-exception repository.
- #141
57574ed
Thanks @belgattitude! - Upgrapde to rollup v3
- #118
2bea0d6
Thanks @belgattitude! - Bundle with rollup v3.0.0
- #96
5b964fd
Thanks @belgattitude! - Disable minification to allow patching (patch-package...)
- #91
9498cb2
Thanks @belgattitude! - Remove hardcoded string in supportsCause function
- #87
a8fbdd2
Thanks @belgattitude! - Fix potential issue with cause that could be undefined
-
#75
89d2dd8
Thanks @belgattitude! - Addedmethod
,code
anderrorId
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);
- #71
f3c423f
Thanks @belgattitude! - Improved documenation and website live
-
#67
7208e7b
Thanks @belgattitude! - Export convertToSerializable and createFromSerializableimport { convertToSerializable, createFromSerializable, } from "@httpx/exception/serializer"; const serializableObject = convertToSerializable(new HttpForbidden()); const exception = createFromSerializable(serializableObject);
- #56
bddd84a
Thanks @belgattitude! - Initial documentation and updated examples
-
#33
67be0fb
Thanks @belgattitude! - Add HttpException json serializer.Two new methods
fromJson
andtoJson
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
-
#51
421b36d
Thanks @belgattitude! - FixError.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
- #40
d1ed899
Thanks @belgattitude! - Support for older browser (class / spread transform)
- #31
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
- #28
c76dd69
Thanks @belgattitude! - Squeeze out 450 bytes for full import
- #25
c153ff8
Thanks @belgattitude! - Improve build
-
#18
6a81535
Thanks @belgattitude! - Improve tree-shaking -
#20
633b1e0
Thanks @belgattitude! - Improve tree-shaking commonjs
- #20
633b1e0
Thanks @belgattitude! - Improve tree-shaking commonjs
- #18
6a81535
Thanks @belgattitude! - Improve tree-shaking
- #16
cdf3333
Thanks @belgattitude! - Add sourcemaps to published dist
- #14
3fe82d8
Thanks @belgattitude! - Internal package in cjs to help dual packaging
76f7fea
Thanks @belgattitude! - Remove browser field
- #11
6168b27
Thanks @belgattitude! - Publish with browser field
281a688
Thanks @belgattitude! - Re-publish with module to test bundlephobia
1b493ad
Thanks @belgattitude! - Rework publishing
- #6
0be9b73
Thanks @belgattitude! - Improve publication and examples
- #4
06204b2
Thanks @belgattitude! - Fix publication