@aglyn/shared-util-errors 1.0.0-beta.143 → 1.0.0-beta.144
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +54 -3
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,7 +1,58 @@
|
|
|
1
1
|
# @aglyn/shared-util-errors
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Error classes shared across the Aglyn packages: an HTTP response error, an upstream-vendor error, and a factory for namespaced, templated errors with stable codes. A small dependency of other Aglyn packages, usable on its own.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
> Beta. Published from the Aglyn monorepo under the `beta` dist-tag; APIs can change between beta releases.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
npm install @aglyn/shared-util-errors@beta
|
|
10
|
+
|
|
11
|
+
No peer dependencies.
|
|
12
|
+
|
|
13
|
+
## What's in it
|
|
14
|
+
|
|
15
|
+
All exported from the package root:
|
|
16
|
+
|
|
17
|
+
- `HttpResponseError(code, message)` - an `Error` carrying an HTTP status in `code` (an `HttpStatusCode` from `@aglyn/shared-data-enums`).
|
|
18
|
+
- `UpstreamServiceError(message, { status, retryable, requestId? })` - a failed call to a third-party service. `message` is meant to be a fixed sentence that is safe to show a customer; the vendor's own wording is not carried on the object. `retryable` says whether the vendor asked to come back later (a rate limit or overload) as opposed to rejecting the request.
|
|
19
|
+
- `NsErrorFactory(scope, namespace, templates, nsDelimiter = '/', scopeDelimiter = ':', defaultMessage = 'Error')` - builds `NsError` instances from a map of flag to message template. `create(flag, payload?)` fills `{$name}` placeholders from the payload; `childFactory(childNamespace, templates?)` derives a factory under a nested namespace.
|
|
20
|
+
- `NsError` - has `code` (`namespace/flag`), `message` and `payload`.
|
|
21
|
+
- `replaceTemplate(template, payload?, options?)` - the `{$name}` placeholder substitution by itself, and `DEFAULT_REPLACER_REGEX`.
|
|
22
|
+
- Types: `ErrorPayload`, `ErrorTagMessages`, `ErrorTagPayloads`, `EventFlag`.
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import {
|
|
28
|
+
NsErrorFactory,
|
|
29
|
+
UpstreamServiceError,
|
|
30
|
+
} from '@aglyn/shared-util-errors'
|
|
31
|
+
|
|
32
|
+
const errors = new NsErrorFactory('my-app', 'files', {
|
|
33
|
+
'not-found': "Could not find file '{$file}'",
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
throw errors.create('not-found', { file: 'foo.txt' })
|
|
38
|
+
} catch (e) {
|
|
39
|
+
// e.code === 'files/not-found'; e.payload.file === 'foo.txt'
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
throw new UpstreamServiceError('The provider is busy. Try again shortly.', {
|
|
43
|
+
status: 429,
|
|
44
|
+
retryable: true,
|
|
45
|
+
})
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Import-time effect
|
|
49
|
+
|
|
50
|
+
This package imports the root of `@aglyn/shared-util-tools`, and that root defines a set of non-enumerable `$_`-prefixed methods on `Array.prototype` when it loads. See that package's README for the exact list.
|
|
51
|
+
|
|
52
|
+
## How it fits
|
|
53
|
+
|
|
54
|
+
A `shared` package: generic, with no knowledge of Aglyn's model. Shared packages may only import other shared packages; this one depends on `@aglyn/shared-data-enums` and `@aglyn/shared-util-tools`. `@aglyn/shared-util-rest-api` and `@aglyn/plugins-ai` depend on it.
|
|
55
|
+
|
|
56
|
+
## License
|
|
57
|
+
|
|
58
|
+
Apache-2.0. Source: https://github.com/aglyn/aglyn/tree/main/libs/shared/util/errors
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aglyn/shared-util-errors",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.144",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"homepage": "https://aglyn.com",
|
|
6
6
|
"repository": {
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"./package.json": "./package.json"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@aglyn/shared-data-enums": "1.0.0-beta.
|
|
29
|
-
"@aglyn/shared-util-tools": "1.0.0-beta.
|
|
28
|
+
"@aglyn/shared-data-enums": "1.0.0-beta.144",
|
|
29
|
+
"@aglyn/shared-util-tools": "1.0.0-beta.144",
|
|
30
30
|
"@swc/helpers": "0.5.23"
|
|
31
31
|
},
|
|
32
32
|
"sideEffects": false,
|