@xavierdev25/rfc7807-errors 0.1.0
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/LICENSE +21 -0
- package/README.md +123 -0
- package/dist/constants.d.ts +3 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +6 -0
- package/dist/constants.js.map +1 -0
- package/dist/exceptions/http-problem-detail.exceptions.d.ts +32 -0
- package/dist/exceptions/http-problem-detail.exceptions.d.ts.map +1 -0
- package/dist/exceptions/http-problem-detail.exceptions.js +109 -0
- package/dist/exceptions/http-problem-detail.exceptions.js.map +1 -0
- package/dist/exceptions/index.d.ts +3 -0
- package/dist/exceptions/index.d.ts.map +1 -0
- package/dist/exceptions/index.js +15 -0
- package/dist/exceptions/index.js.map +1 -0
- package/dist/exceptions/problem-detail.exception.d.ts +20 -0
- package/dist/exceptions/problem-detail.exception.d.ts.map +1 -0
- package/dist/exceptions/problem-detail.exception.js +38 -0
- package/dist/exceptions/problem-detail.exception.js.map +1 -0
- package/dist/filters/index.d.ts +2 -0
- package/dist/filters/index.d.ts.map +1 -0
- package/dist/filters/index.js +6 -0
- package/dist/filters/index.js.map +1 -0
- package/dist/filters/rfc7807-exception.filter.d.ts +15 -0
- package/dist/filters/rfc7807-exception.filter.d.ts.map +1 -0
- package/dist/filters/rfc7807-exception.filter.js +143 -0
- package/dist/filters/rfc7807-exception.filter.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/index.d.ts +4 -0
- package/dist/interfaces/index.d.ts.map +1 -0
- package/dist/interfaces/index.js +3 -0
- package/dist/interfaces/index.js.map +1 -0
- package/dist/interfaces/problem-detail-serializer.interface.d.ts +6 -0
- package/dist/interfaces/problem-detail-serializer.interface.d.ts.map +1 -0
- package/dist/interfaces/problem-detail-serializer.interface.js +3 -0
- package/dist/interfaces/problem-detail-serializer.interface.js.map +1 -0
- package/dist/interfaces/problem-detail.interface.d.ts +9 -0
- package/dist/interfaces/problem-detail.interface.d.ts.map +1 -0
- package/dist/interfaces/problem-detail.interface.js +3 -0
- package/dist/interfaces/problem-detail.interface.js.map +1 -0
- package/dist/interfaces/rfc7807-module-options.interface.d.ts +19 -0
- package/dist/interfaces/rfc7807-module-options.interface.d.ts.map +1 -0
- package/dist/interfaces/rfc7807-module-options.interface.js +3 -0
- package/dist/interfaces/rfc7807-module-options.interface.js.map +1 -0
- package/dist/rfc7807.module.d.ts +8 -0
- package/dist/rfc7807.module.d.ts.map +1 -0
- package/dist/rfc7807.module.js +104 -0
- package/dist/rfc7807.module.js.map +1 -0
- package/dist/serializers/index.d.ts +2 -0
- package/dist/serializers/index.d.ts.map +1 -0
- package/dist/serializers/index.js +6 -0
- package/dist/serializers/index.js.map +1 -0
- package/dist/serializers/json-problem-detail.serializer.d.ts +7 -0
- package/dist/serializers/json-problem-detail.serializer.d.ts.map +1 -0
- package/dist/serializers/json-problem-detail.serializer.js +26 -0
- package/dist/serializers/json-problem-detail.serializer.js.map +1 -0
- package/package.json +70 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Xavier Montaño
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# @xavierdev25/rfc7807-errors
|
|
2
|
+
|
|
3
|
+
> Global NestJS exception filter implementing **RFC 7807 Problem Details** (`application/problem+json`) for HTTP APIs.
|
|
4
|
+
|
|
5
|
+
Turns every error your API throws — your own domain errors, NestJS `HttpException`s, and unexpected crashes — into a single, standard, machine-readable error shape:
|
|
6
|
+
|
|
7
|
+
```json
|
|
8
|
+
{
|
|
9
|
+
"type": "https://api.example.com/errors/not-found",
|
|
10
|
+
"title": "Not Found",
|
|
11
|
+
"status": 404,
|
|
12
|
+
"detail": "Transaction with ID '…' was not found.",
|
|
13
|
+
"instance": "/transactions/123",
|
|
14
|
+
"transactionId": "123"
|
|
15
|
+
}
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Built with SOLID in mind: an abstract `ProblemDetailException`, eight concrete LSP-correct subclasses, a framework-agnostic filter (Express/Fastify via `HttpAdapterHost`), and a pluggable serializer (DIP).
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pnpm add @xavierdev25/rfc7807-errors
|
|
24
|
+
# peer deps: @nestjs/common, @nestjs/core, rxjs
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Quick start
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import { Module } from '@nestjs/common';
|
|
31
|
+
import { Rfc7807Module } from '@xavierdev25/rfc7807-errors';
|
|
32
|
+
|
|
33
|
+
@Module({
|
|
34
|
+
imports: [
|
|
35
|
+
Rfc7807Module.forRoot({
|
|
36
|
+
// Type URIs become `${typeBaseUri}/${error-slug}` (default: 'about:blank')
|
|
37
|
+
typeBaseUri: 'https://api.example.com/errors',
|
|
38
|
+
// Stack traces are added only when NODE_ENV !== 'production'
|
|
39
|
+
includeStackTrace: process.env.NODE_ENV !== 'production',
|
|
40
|
+
// Hook for logging / metrics / error tracking
|
|
41
|
+
onProblem: (problem, exception) => logger.error(problem.title, exception),
|
|
42
|
+
}),
|
|
43
|
+
],
|
|
44
|
+
})
|
|
45
|
+
export class AppModule {}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
`forRoot` registers the `Rfc7807ExceptionFilter` globally (`APP_FILTER`). No manual `useGlobalFilters` needed.
|
|
49
|
+
|
|
50
|
+
## Throwing problems
|
|
51
|
+
|
|
52
|
+
Eight ready-made exceptions, one per common HTTP status:
|
|
53
|
+
|
|
54
|
+
| Class | Status |
|
|
55
|
+
| --- | --- |
|
|
56
|
+
| `BadRequestProblem` | 400 |
|
|
57
|
+
| `UnauthorizedProblem` | 401 |
|
|
58
|
+
| `ForbiddenProblem` | 403 |
|
|
59
|
+
| `NotFoundProblem` | 404 |
|
|
60
|
+
| `ConflictProblem` | 409 |
|
|
61
|
+
| `UnprocessableEntityProblem` | 422 |
|
|
62
|
+
| `TooManyRequestsProblem` | 429 |
|
|
63
|
+
| `InternalServerErrorProblem` | 500 |
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
import { ConflictProblem } from '@xavierdev25/rfc7807-errors';
|
|
67
|
+
|
|
68
|
+
throw new ConflictProblem({
|
|
69
|
+
detail: 'A transaction with this idempotency key already exists.',
|
|
70
|
+
instance: request.url, // optional; the filter fills it from the request URL
|
|
71
|
+
extensions: { idempotencyKey }, // any extra members are merged into the body
|
|
72
|
+
});
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Custom domain errors
|
|
76
|
+
|
|
77
|
+
Subclass a problem so your domain layer throws meaningful, typed errors that still serialize to RFC 7807:
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
import { NotFoundProblem } from '@xavierdev25/rfc7807-errors';
|
|
81
|
+
|
|
82
|
+
export class TransactionNotFoundError extends NotFoundProblem {
|
|
83
|
+
constructor(id: string) {
|
|
84
|
+
super({
|
|
85
|
+
type: 'https://api.example.com/errors/transaction-not-found',
|
|
86
|
+
detail: `Transaction with ID '${id}' was not found.`,
|
|
87
|
+
extensions: { transactionId: id },
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Async configuration
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
Rfc7807Module.forRootAsync({
|
|
97
|
+
imports: [ConfigModule],
|
|
98
|
+
inject: [ConfigService],
|
|
99
|
+
useFactory: (config: ConfigService) => ({
|
|
100
|
+
typeBaseUri: config.get('ERRORS_BASE_URI'),
|
|
101
|
+
includeStackTrace: config.get('NODE_ENV') !== 'production',
|
|
102
|
+
}),
|
|
103
|
+
});
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
`useClass` and `useExisting` (via `Rfc7807OptionsFactory`) are also supported.
|
|
107
|
+
|
|
108
|
+
## What the filter handles
|
|
109
|
+
|
|
110
|
+
1. **`ProblemDetailException`** (yours) → serialized as-is via `toProblemDetail()`.
|
|
111
|
+
2. **NestJS `HttpException`** → mapped to RFC 7807 (validation arrays become an `errors` member).
|
|
112
|
+
3. **Anything else** → `500`, with the detail **masked** in production to avoid leaking internals.
|
|
113
|
+
|
|
114
|
+
## Options
|
|
115
|
+
|
|
116
|
+
| Option | Type | Default | Description |
|
|
117
|
+
| --- | --- | --- | --- |
|
|
118
|
+
| `typeBaseUri` | `string` | `'about:blank'` | Prefix for the `type` URI (`{base}/{slug}`). |
|
|
119
|
+
| `includeStackTrace` | `boolean` | `false` | Add `stackTrace` to the body (never in production). |
|
|
120
|
+
| `onProblem` | `(problem, exception) => void` | – | Side-effect hook (logging/metrics). |
|
|
121
|
+
| `serializer` | `IProblemDetailSerializer` | `JsonProblemDetailSerializer` | Custom output serializer (DIP). |
|
|
122
|
+
|
|
123
|
+
Content type: **`application/problem+json`**. See [RFC 7807](https://www.rfc-editor.org/rfc/rfc7807).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,eAAe,eAA4B,CAAC;AAGzD,eAAO,MAAM,kBAAkB,eAA+B,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RFC7807_SERIALIZER = exports.RFC7807_OPTIONS = void 0;
|
|
4
|
+
exports.RFC7807_OPTIONS = Symbol('RFC7807_OPTIONS');
|
|
5
|
+
exports.RFC7807_SERIALIZER = Symbol('RFC7807_SERIALIZER');
|
|
6
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAQa,QAAA,eAAe,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAC;AAG5C,QAAA,kBAAkB,GAAG,MAAM,CAAC,oBAAoB,CAAC,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ProblemDetailException } from './problem-detail.exception';
|
|
2
|
+
export interface HttpProblemOptions {
|
|
3
|
+
detail?: string;
|
|
4
|
+
instance?: string;
|
|
5
|
+
type?: string;
|
|
6
|
+
extensions?: Record<string, unknown>;
|
|
7
|
+
}
|
|
8
|
+
export declare class BadRequestProblem extends ProblemDetailException {
|
|
9
|
+
constructor(options?: HttpProblemOptions);
|
|
10
|
+
}
|
|
11
|
+
export declare class UnauthorizedProblem extends ProblemDetailException {
|
|
12
|
+
constructor(options?: HttpProblemOptions);
|
|
13
|
+
}
|
|
14
|
+
export declare class ForbiddenProblem extends ProblemDetailException {
|
|
15
|
+
constructor(options?: HttpProblemOptions);
|
|
16
|
+
}
|
|
17
|
+
export declare class NotFoundProblem extends ProblemDetailException {
|
|
18
|
+
constructor(options?: HttpProblemOptions);
|
|
19
|
+
}
|
|
20
|
+
export declare class ConflictProblem extends ProblemDetailException {
|
|
21
|
+
constructor(options?: HttpProblemOptions);
|
|
22
|
+
}
|
|
23
|
+
export declare class UnprocessableEntityProblem extends ProblemDetailException {
|
|
24
|
+
constructor(options?: HttpProblemOptions);
|
|
25
|
+
}
|
|
26
|
+
export declare class TooManyRequestsProblem extends ProblemDetailException {
|
|
27
|
+
constructor(options?: HttpProblemOptions);
|
|
28
|
+
}
|
|
29
|
+
export declare class InternalServerErrorProblem extends ProblemDetailException {
|
|
30
|
+
constructor(options?: HttpProblemOptions);
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=http-problem-detail.exceptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-problem-detail.exceptions.d.ts","sourceRoot":"","sources":["../../src/exceptions/http-problem-detail.exceptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAMpE,MAAM,WAAW,kBAAkB;IAEjC,MAAM,CAAC,EAAE,MAAM,CAAC;IAGhB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAGlB,IAAI,CAAC,EAAE,MAAM,CAAC;IAGd,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACtC;AAQD,qBAAa,iBAAkB,SAAQ,sBAAsB;gBAC/C,OAAO,GAAE,kBAAuB;CAU7C;AAQD,qBAAa,mBAAoB,SAAQ,sBAAsB;gBACjD,OAAO,GAAE,kBAAuB;CAU7C;AAOD,qBAAa,gBAAiB,SAAQ,sBAAsB;gBAC9C,OAAO,GAAE,kBAAuB;CAU7C;AAQD,qBAAa,eAAgB,SAAQ,sBAAsB;gBAC7C,OAAO,GAAE,kBAAuB;CAU7C;AAQD,qBAAa,eAAgB,SAAQ,sBAAsB;gBAC7C,OAAO,GAAE,kBAAuB;CAU7C;AAQD,qBAAa,0BAA2B,SAAQ,sBAAsB;gBACxD,OAAO,GAAE,kBAAuB;CAU7C;AAQD,qBAAa,sBAAuB,SAAQ,sBAAsB;gBACpD,OAAO,GAAE,kBAAuB;CAU7C;AAQD,qBAAa,0BAA2B,SAAQ,sBAAsB;gBACxD,OAAO,GAAE,kBAAuB;CAU7C"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InternalServerErrorProblem = exports.TooManyRequestsProblem = exports.UnprocessableEntityProblem = exports.ConflictProblem = exports.NotFoundProblem = exports.ForbiddenProblem = exports.UnauthorizedProblem = exports.BadRequestProblem = void 0;
|
|
4
|
+
const problem_detail_exception_1 = require("./problem-detail.exception");
|
|
5
|
+
class BadRequestProblem extends problem_detail_exception_1.ProblemDetailException {
|
|
6
|
+
constructor(options = {}) {
|
|
7
|
+
super({
|
|
8
|
+
type: options.type ?? 'about:blank',
|
|
9
|
+
title: 'Bad Request',
|
|
10
|
+
status: 400,
|
|
11
|
+
detail: options.detail,
|
|
12
|
+
instance: options.instance,
|
|
13
|
+
extensions: options.extensions,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.BadRequestProblem = BadRequestProblem;
|
|
18
|
+
class UnauthorizedProblem extends problem_detail_exception_1.ProblemDetailException {
|
|
19
|
+
constructor(options = {}) {
|
|
20
|
+
super({
|
|
21
|
+
type: options.type ?? 'about:blank',
|
|
22
|
+
title: 'Unauthorized',
|
|
23
|
+
status: 401,
|
|
24
|
+
detail: options.detail,
|
|
25
|
+
instance: options.instance,
|
|
26
|
+
extensions: options.extensions,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.UnauthorizedProblem = UnauthorizedProblem;
|
|
31
|
+
class ForbiddenProblem extends problem_detail_exception_1.ProblemDetailException {
|
|
32
|
+
constructor(options = {}) {
|
|
33
|
+
super({
|
|
34
|
+
type: options.type ?? 'about:blank',
|
|
35
|
+
title: 'Forbidden',
|
|
36
|
+
status: 403,
|
|
37
|
+
detail: options.detail,
|
|
38
|
+
instance: options.instance,
|
|
39
|
+
extensions: options.extensions,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.ForbiddenProblem = ForbiddenProblem;
|
|
44
|
+
class NotFoundProblem extends problem_detail_exception_1.ProblemDetailException {
|
|
45
|
+
constructor(options = {}) {
|
|
46
|
+
super({
|
|
47
|
+
type: options.type ?? 'about:blank',
|
|
48
|
+
title: 'Not Found',
|
|
49
|
+
status: 404,
|
|
50
|
+
detail: options.detail,
|
|
51
|
+
instance: options.instance,
|
|
52
|
+
extensions: options.extensions,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.NotFoundProblem = NotFoundProblem;
|
|
57
|
+
class ConflictProblem extends problem_detail_exception_1.ProblemDetailException {
|
|
58
|
+
constructor(options = {}) {
|
|
59
|
+
super({
|
|
60
|
+
type: options.type ?? 'about:blank',
|
|
61
|
+
title: 'Conflict',
|
|
62
|
+
status: 409,
|
|
63
|
+
detail: options.detail,
|
|
64
|
+
instance: options.instance,
|
|
65
|
+
extensions: options.extensions,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.ConflictProblem = ConflictProblem;
|
|
70
|
+
class UnprocessableEntityProblem extends problem_detail_exception_1.ProblemDetailException {
|
|
71
|
+
constructor(options = {}) {
|
|
72
|
+
super({
|
|
73
|
+
type: options.type ?? 'about:blank',
|
|
74
|
+
title: 'Unprocessable Entity',
|
|
75
|
+
status: 422,
|
|
76
|
+
detail: options.detail,
|
|
77
|
+
instance: options.instance,
|
|
78
|
+
extensions: options.extensions,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.UnprocessableEntityProblem = UnprocessableEntityProblem;
|
|
83
|
+
class TooManyRequestsProblem extends problem_detail_exception_1.ProblemDetailException {
|
|
84
|
+
constructor(options = {}) {
|
|
85
|
+
super({
|
|
86
|
+
type: options.type ?? 'about:blank',
|
|
87
|
+
title: 'Too Many Requests',
|
|
88
|
+
status: 429,
|
|
89
|
+
detail: options.detail,
|
|
90
|
+
instance: options.instance,
|
|
91
|
+
extensions: options.extensions,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports.TooManyRequestsProblem = TooManyRequestsProblem;
|
|
96
|
+
class InternalServerErrorProblem extends problem_detail_exception_1.ProblemDetailException {
|
|
97
|
+
constructor(options = {}) {
|
|
98
|
+
super({
|
|
99
|
+
type: options.type ?? 'about:blank',
|
|
100
|
+
title: 'Internal Server Error',
|
|
101
|
+
status: 500,
|
|
102
|
+
detail: options.detail,
|
|
103
|
+
instance: options.instance,
|
|
104
|
+
extensions: options.extensions,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
exports.InternalServerErrorProblem = InternalServerErrorProblem;
|
|
109
|
+
//# sourceMappingURL=http-problem-detail.exceptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-problem-detail.exceptions.js","sourceRoot":"","sources":["../../src/exceptions/http-problem-detail.exceptions.ts"],"names":[],"mappings":";;;AAAA,yEAAoE;AA0BpE,MAAa,iBAAkB,SAAQ,iDAAsB;IAC3D,YAAY,UAA8B,EAAE;QAC1C,KAAK,CAAC;YACJ,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,aAAa;YACnC,KAAK,EAAE,aAAa;YACpB,MAAM,EAAE,GAAG;YACX,MAA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AC/B,CAAC,CAAC;IACL,CAAC;CACF;AAXD,gEAWC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { ProblemDetailException, ProblemDetailParams, } from './problem-detail.exception';
|
|
2
|
+
export { HttpProblemOptions, BadRequestProblem, UnauthorizedProblem, ForbiddenProblem, NotFoundProblem, ConflictProblem, UnprocessableEntityProblem, TooManyRequestsProblem, InternalServerErrorProblem, } from './http-problem-detail.exceptions';
|
|
3
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/exceptions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,mBAAmB,GACpB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,0BAA0B,EAC1B,sBAAsB,EACtB,0BAA0B,GAC3B,MAAM,kCAAkC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InternalServerErrorProblem = exports.TooManyRequestsProblem = exports.UnprocessableEntityProblem = exports.ConflictProblem = exports.NotFoundProblem = exports.ForbiddenProblem = exports.UnauthorizedProblem = exports.BadRequestProblem = exports.ProblemDetailException = void 0;
|
|
4
|
+
var problem_detail_exception_1 = require("./problem-detail.exception");
|
|
5
|
+
Object.defineProperty(exports, "ProblemDetailException", { enumerable: true, get: function () { return problem_detail_exception_1.ProblemDetailException; } });
|
|
6
|
+
var http_problem_detail_exceptions_1 = require("./http-problem-detail.exceptions");
|
|
7
|
+
Object.defineProperty(exports, "BadRequestProblem", { enumerable: true, get: function () { return http_problem_detail_exceptions_1.BadRequestProblem; } });
|
|
8
|
+
Object.defineProperty(exports, "UnauthorizedProblem", { enumerable: true, get: function () { return http_problem_detail_exceptions_1.UnauthorizedProblem; } });
|
|
9
|
+
Object.defineProperty(exports, "ForbiddenProblem", { enumerable: true, get: function () { return http_problem_detail_exceptions_1.ForbiddenProblem; } });
|
|
10
|
+
Object.defineProperty(exports, "NotFoundProblem", { enumerable: true, get: function () { return http_problem_detail_exceptions_1.NotFoundProblem; } });
|
|
11
|
+
Object.defineProperty(exports, "ConflictProblem", { enumerable: true, get: function () { return http_problem_detail_exceptions_1.ConflictProblem; } });
|
|
12
|
+
Object.defineProperty(exports, "UnprocessableEntityProblem", { enumerable: true, get: function () { return http_problem_detail_exceptions_1.UnprocessableEntityProblem; } });
|
|
13
|
+
Object.defineProperty(exports, "TooManyRequestsProblem", { enumerable: true, get: function () { return http_problem_detail_exceptions_1.TooManyRequestsProblem; } });
|
|
14
|
+
Object.defineProperty(exports, "InternalServerErrorProblem", { enumerable: true, get: function () { return http_problem_detail_exceptions_1.InternalServerErrorProblem; } });
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/exceptions/index.ts"],"names":[],"mappings":";;;AAAA,uEAGoC;AAFlC,kIAAA,sBAAsB,OAAA;AAGxB,mFAU0C;AARxC,mIAAA,iBAAiB,OAAA;AACjB,qIAAA,mBAAmB,OAAA;AACnB,kIAAA,gBAAgB,OAAA;AAChB,iIAAA,eAAe,OAAA;AACf,iIAAA,eAAe,OAAA;AACf,4IAAA,0BAA0B,OAAA;AAC1B,wIAAA,sBAAsB,OAAA;AACtB,4IAAA,0BAA0B,OAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { IProblemDetail } from '../interfaces/problem-detail.interface';
|
|
2
|
+
export interface ProblemDetailParams {
|
|
3
|
+
type?: string;
|
|
4
|
+
title: string;
|
|
5
|
+
status: number;
|
|
6
|
+
detail?: string;
|
|
7
|
+
instance?: string;
|
|
8
|
+
extensions?: Record<string, unknown>;
|
|
9
|
+
}
|
|
10
|
+
export declare abstract class ProblemDetailException extends Error {
|
|
11
|
+
readonly type: string;
|
|
12
|
+
readonly title: string;
|
|
13
|
+
readonly status: number;
|
|
14
|
+
readonly detail?: string;
|
|
15
|
+
readonly instance?: string;
|
|
16
|
+
readonly extensions: Record<string, unknown>;
|
|
17
|
+
constructor(params: ProblemDetailParams);
|
|
18
|
+
toProblemDetail(): IProblemDetail;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=problem-detail.exception.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"problem-detail.exception.d.ts","sourceRoot":"","sources":["../../src/exceptions/problem-detail.exception.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AAOxE,MAAM,WAAW,mBAAmB;IAKlC,IAAI,CAAC,EAAE,MAAM,CAAC;IAGd,KAAK,EAAE,MAAM,CAAC;IAGd,MAAM,EAAE,MAAM,CAAC;IAGf,MAAM,CAAC,EAAE,MAAM,CAAC;IAGhB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAGlB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACtC;AAaD,8BAAsB,sBAAuB,SAAQ,KAAK;IAExD,SAAgB,IAAI,EAAE,MAAM,CAAC;IAG7B,SAAgB,KAAK,EAAE,MAAM,CAAC;IAG9B,SAAgB,MAAM,EAAE,MAAM,CAAC;IAG/B,SAAgB,MAAM,CAAC,EAAE,MAAM,CAAC;IAGhC,SAAgB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAGlC,SAAgB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBAExC,MAAM,EAAE,mBAAmB;IA0BvC,eAAe,IAAI,cAAc;CAsBlC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProblemDetailException = void 0;
|
|
4
|
+
class ProblemDetailException extends Error {
|
|
5
|
+
constructor(params) {
|
|
6
|
+
super(params.detail ?? params.title);
|
|
7
|
+
this.type = params.type ?? 'about:blank';
|
|
8
|
+
this.title = params.title;
|
|
9
|
+
this.status = params.status;
|
|
10
|
+
this.detail = params.detail;
|
|
11
|
+
this.instance = params.instance;
|
|
12
|
+
this.extensions = params.extensions ?? {};
|
|
13
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
14
|
+
if (Error.captureStackTrace) {
|
|
15
|
+
Error.captureStackTrace(this, this.constructor);
|
|
16
|
+
}
|
|
17
|
+
this.name = this.constructor.name;
|
|
18
|
+
}
|
|
19
|
+
toProblemDetail() {
|
|
20
|
+
const problem = {
|
|
21
|
+
type: this.type,
|
|
22
|
+
title: this.title,
|
|
23
|
+
status: this.status,
|
|
24
|
+
};
|
|
25
|
+
if (this.detail !== undefined) {
|
|
26
|
+
problem.detail = this.detail;
|
|
27
|
+
}
|
|
28
|
+
if (this.instance !== undefined) {
|
|
29
|
+
problem.instance = this.instance;
|
|
30
|
+
}
|
|
31
|
+
for (const [key, value] of Object.entries(this.extensions)) {
|
|
32
|
+
problem[key] = value;
|
|
33
|
+
}
|
|
34
|
+
return problem;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.ProblemDetailException = ProblemDetailException;
|
|
38
|
+
//# sourceMappingURL=problem-detail.exception.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"problem-detail.exception.js","sourceRoot":"","sources":["../../src/exceptions/problem-detail.exception.ts"],"names":[],"mappings":";;;AAyCA,MAAsB,sBAAuB,SAAQ,KAAK;IAmBxD,YAAY,MAA2B;QACrC,KAAK,CAAC,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC;QAErC,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,IAAI,aAAa,CAAC;QACzC,IAAI,CAAC,KAAK,GAAG,MAAM,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.d.ts","sourceRoot":"","sources":["../../src/filters/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Rfc7807ExceptionFilter = void 0;
|
|
4
|
+
var rfc7807_exception_filter_1 = require("./rfc7807-exception.filter");
|
|
5
|
+
Object.defineProperty(exports, "Rfc7807ExceptionFilter", { enumerable: true, get: function () { return rfc7807_exception_filter_1.Rfc7807ExceptionFilter; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/filters/index.ts"],"names":[],"mappings":";;;AAAA,uEAAoE;AAA3D,kIAAA,sBAAsB,OAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ArgumentsHost, ExceptionFilter } from '@nestjs/common';
|
|
2
|
+
import { IProblemDetailSerializer } from '../interfaces/problem-detail-serializer.interface';
|
|
3
|
+
import { Rfc7807ModuleOptions } from '../interfaces/rfc7807-module-options.interface';
|
|
4
|
+
export declare class Rfc7807ExceptionFilter implements ExceptionFilter {
|
|
5
|
+
private readonly serializer;
|
|
6
|
+
private readonly options;
|
|
7
|
+
constructor(serializer?: IProblemDetailSerializer, options?: Rfc7807ModuleOptions);
|
|
8
|
+
catch(exception: unknown, host: ArgumentsHost): void;
|
|
9
|
+
private buildProblemDetail;
|
|
10
|
+
private fromHttpException;
|
|
11
|
+
private fromUnknownError;
|
|
12
|
+
private resolveTypeUri;
|
|
13
|
+
private applyTypeBaseUri;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=rfc7807-exception.filter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rfc7807-exception.filter.d.ts","sourceRoot":"","sources":["../../src/filters/rfc7807-exception.filter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAEb,eAAe,EAKhB,MAAM,gBAAgB,CAAC;AAMxB,OAAO,EAAE,wBAAwB,EAAE,MAAM,mDAAmD,CAAC;AAC7F,OAAO,EAAE,oBAAoB,EAAE,MAAM,gDAAgD,CAAC;AAqCtF,qBACa,sBAAuB,YAAW,eAAe;IAC5D,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA2B;IACtD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAuB;gBAK7C,UAAU,CAAC,EAAE,wBAAwB,EAGrC,OAAO,CAAC,EAAE,oBAAoB;IAUhC,KAAK,CAAC,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,aAAa,GAAG,IAAI;IAqCpD,OAAO,CAAC,kBAAkB;IA0B1B,OAAO,CAAC,iBAAiB;IAyCzB,OAAO,CAAC,gBAAgB;IAwBxB,OAAO,CAAC,cAAc;IAoBtB,OAAO,CAAC,gBAAgB;CAUzB"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.Rfc7807ExceptionFilter = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const constants_1 = require("../constants");
|
|
18
|
+
const problem_detail_exception_1 = require("../exceptions/problem-detail.exception");
|
|
19
|
+
const json_problem_detail_serializer_1 = require("../serializers/json-problem-detail.serializer");
|
|
20
|
+
const HTTP_STATUS_TITLES = {
|
|
21
|
+
[common_1.HttpStatus.BAD_REQUEST]: 'Bad Request',
|
|
22
|
+
[common_1.HttpStatus.UNAUTHORIZED]: 'Unauthorized',
|
|
23
|
+
[common_1.HttpStatus.FORBIDDEN]: 'Forbidden',
|
|
24
|
+
[common_1.HttpStatus.NOT_FOUND]: 'Not Found',
|
|
25
|
+
[common_1.HttpStatus.METHOD_NOT_ALLOWED]: 'Method Not Allowed',
|
|
26
|
+
[common_1.HttpStatus.CONFLICT]: 'Conflict',
|
|
27
|
+
[common_1.HttpStatus.GONE]: 'Gone',
|
|
28
|
+
[common_1.HttpStatus.UNPROCESSABLE_ENTITY]: 'Unprocessable Entity',
|
|
29
|
+
[common_1.HttpStatus.TOO_MANY_REQUESTS]: 'Too Many Requests',
|
|
30
|
+
[common_1.HttpStatus.INTERNAL_SERVER_ERROR]: 'Internal Server Error',
|
|
31
|
+
[common_1.HttpStatus.NOT_IMPLEMENTED]: 'Not Implemented',
|
|
32
|
+
[common_1.HttpStatus.BAD_GATEWAY]: 'Bad Gateway',
|
|
33
|
+
[common_1.HttpStatus.SERVICE_UNAVAILABLE]: 'Service Unavailable',
|
|
34
|
+
[common_1.HttpStatus.GATEWAY_TIMEOUT]: 'Gateway Timeout',
|
|
35
|
+
};
|
|
36
|
+
let Rfc7807ExceptionFilter = class Rfc7807ExceptionFilter {
|
|
37
|
+
constructor(serializer, options) {
|
|
38
|
+
this.serializer = serializer ?? new json_problem_detail_serializer_1.JsonProblemDetailSerializer();
|
|
39
|
+
this.options = options ?? {};
|
|
40
|
+
}
|
|
41
|
+
catch(exception, host) {
|
|
42
|
+
const ctx = host.switchToHttp();
|
|
43
|
+
const response = ctx.getResponse();
|
|
44
|
+
const request = ctx.getRequest();
|
|
45
|
+
const problem = this.buildProblemDetail(exception, request);
|
|
46
|
+
if (this.options.includeStackTrace &&
|
|
47
|
+
process.env.NODE_ENV !== 'production' &&
|
|
48
|
+
exception instanceof Error) {
|
|
49
|
+
problem.stackTrace = exception.stack;
|
|
50
|
+
}
|
|
51
|
+
if (this.options.onProblem && exception instanceof Error) {
|
|
52
|
+
this.options.onProblem(problem, exception);
|
|
53
|
+
}
|
|
54
|
+
const serialized = this.serializer.serialize(problem);
|
|
55
|
+
response
|
|
56
|
+
.status(problem.status)
|
|
57
|
+
.setHeader('Content-Type', this.serializer.contentType)
|
|
58
|
+
.send(serialized);
|
|
59
|
+
}
|
|
60
|
+
buildProblemDetail(exception, request) {
|
|
61
|
+
if (exception instanceof problem_detail_exception_1.ProblemDetailException) {
|
|
62
|
+
const problem = exception.toProblemDetail();
|
|
63
|
+
if (!problem.instance) {
|
|
64
|
+
problem.instance = request.url;
|
|
65
|
+
}
|
|
66
|
+
return this.applyTypeBaseUri(problem);
|
|
67
|
+
}
|
|
68
|
+
if (exception instanceof common_1.HttpException) {
|
|
69
|
+
return this.fromHttpException(exception, request);
|
|
70
|
+
}
|
|
71
|
+
return this.fromUnknownError(exception, request);
|
|
72
|
+
}
|
|
73
|
+
fromHttpException(exception, request) {
|
|
74
|
+
const status = exception.getStatus();
|
|
75
|
+
const exceptionResponse = exception.getResponse();
|
|
76
|
+
const title = HTTP_STATUS_TITLES[status] ?? `HTTP Error ${status}`;
|
|
77
|
+
const problem = {
|
|
78
|
+
type: this.resolveTypeUri(title),
|
|
79
|
+
title,
|
|
80
|
+
status,
|
|
81
|
+
instance: request.url,
|
|
82
|
+
};
|
|
83
|
+
if (typeof exceptionResponse === 'string') {
|
|
84
|
+
problem.detail = exceptionResponse;
|
|
85
|
+
}
|
|
86
|
+
else if (typeof exceptionResponse === 'object' &&
|
|
87
|
+
exceptionResponse !== null) {
|
|
88
|
+
const responseObj = exceptionResponse;
|
|
89
|
+
if (typeof responseObj.message === 'string') {
|
|
90
|
+
problem.detail = responseObj.message;
|
|
91
|
+
}
|
|
92
|
+
else if (Array.isArray(responseObj.message)) {
|
|
93
|
+
problem.detail = 'Validation failed';
|
|
94
|
+
problem.errors = responseObj.message;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return problem;
|
|
98
|
+
}
|
|
99
|
+
fromUnknownError(exception, request) {
|
|
100
|
+
const isProduction = process.env.NODE_ENV === 'production';
|
|
101
|
+
const detail = isProduction
|
|
102
|
+
? 'An unexpected error occurred'
|
|
103
|
+
: exception instanceof Error
|
|
104
|
+
? exception.message
|
|
105
|
+
: String(exception);
|
|
106
|
+
return {
|
|
107
|
+
type: this.resolveTypeUri('Internal Server Error'),
|
|
108
|
+
title: 'Internal Server Error',
|
|
109
|
+
status: common_1.HttpStatus.INTERNAL_SERVER_ERROR,
|
|
110
|
+
detail,
|
|
111
|
+
instance: request.url,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
resolveTypeUri(title) {
|
|
115
|
+
if (!this.options.typeBaseUri ||
|
|
116
|
+
this.options.typeBaseUri === 'about:blank') {
|
|
117
|
+
return 'about:blank';
|
|
118
|
+
}
|
|
119
|
+
const slug = title
|
|
120
|
+
.toLowerCase()
|
|
121
|
+
.replace(/\s+/g, '-')
|
|
122
|
+
.replace(/[^a-z0-9-]/g, '');
|
|
123
|
+
return `${this.options.typeBaseUri.replace(/\/+$/, '')}/${slug}`;
|
|
124
|
+
}
|
|
125
|
+
applyTypeBaseUri(problem) {
|
|
126
|
+
if (problem.type === 'about:blank' &&
|
|
127
|
+
this.options.typeBaseUri &&
|
|
128
|
+
this.options.typeBaseUri !== 'about:blank') {
|
|
129
|
+
problem.type = this.resolveTypeUri(problem.title);
|
|
130
|
+
}
|
|
131
|
+
return problem;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
exports.Rfc7807ExceptionFilter = Rfc7807ExceptionFilter;
|
|
135
|
+
exports.Rfc7807ExceptionFilter = Rfc7807ExceptionFilter = __decorate([
|
|
136
|
+
(0, common_1.Catch)(),
|
|
137
|
+
__param(0, (0, common_1.Optional)()),
|
|
138
|
+
__param(0, (0, common_1.Inject)(constants_1.RFC7807_SERIALIZER)),
|
|
139
|
+
__param(1, (0, common_1.Optional)()),
|
|
140
|
+
__param(1, (0, common_1.Inject)(constants_1.RFC7807_OPTIONS)),
|
|
141
|
+
__metadata("design:paramtypes", [Object, Object])
|
|
142
|
+
], Rfc7807ExceptionFilter);
|
|
143
|
+
//# sourceMappingURL=rfc7807-exception.filter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rfc7807-exception.filter.js","sourceRoot":"","sources":["../../src/filters/rfc7807-exception.filter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAQwB;AAGxB,4CAAmE;AACnE,qFAAgF;AAIhF,kGAA4F;AAM5F,MAAM,kBAAkB,GAA2B;IACjD,CAAC,mBAAU,CAAC,WAAW,CAAC,EAAE,aAAa;IACvC,CAAC,mBAAU,CAAC,YAAY,CAAC,EAAE,cAAc;IACzC,CAAC,mBAAU,CAAC,SAAS,CAAC,EAAE,WAAW;IACnC,CAAC,mBAAU,CAAC,SAAS,CAAC,EAAE,WAAW;IACnC,CAAC,mBAAU,CAAC,kBAAkB,CAAC,EAAE,oBAAoB;IACrD,CAAC,mBAAU,CAAC,QAAQ,CAAC,EAAE,UAAU;IACjC,CAAC,mBAAU,CAAC,IAAI,CAAC,EAAE,MAAM;IACzB,CAAC,mBAAU,CAAC,oBAAoB,CAAC,EAAE,sBAAsB;IACzD,CAAC,mBAAU,CAAC,iBAAiB,CAAC,EAAE,mBAAmB;IACnD,CAAC,mBAAU,CAAC,qBAAqB,CAAC,EAAE,uBAAuB;IAC3D,CAAC,mBAAU,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,EAAE,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC;IACnE,CAAC;IAMO,gBAAgB,CAAC,OAAuB;QAC9C,IACE,OAAO,CAAC,IAAI,KAAK,aAAa;YAC9B,IAAI,CAAC,OAAO,CAAC,WAAW;YACxB,IAAI,CAAC,OAAO,CAAC,WAAW,KAAK,aAAa,EAC1C,CAAC;YACD,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACpD,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;CACF,CAAA;AAlLY,wDAAsB;iCAAtB,sBAAsB;IADlC,IAAA,cAAK,GAAE;IAMH,WAAA,IAAA,iBAAQ,GAAE,CAAA;IACV,WAAA,IAAA,eAAM,EAAC,8BAAkB,CAAC,CAAA;IAE1B,WAAA,IAAA,iBAAQ,GAAE,CAAA;IACV,WAAA,IAAA,eAAM,EAAC,2BAAe,CAAC,CAAA;;GATf,sBAAsB,CAkLlC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { Rfc7807Module } from './rfc7807.module';
|
|
2
|
+
export { RFC7807_OPTIONS, RFC7807_SERIALIZER } from './constants';
|
|
3
|
+
export { IProblemDetail, IProblemDetailSerializer, Rfc7807ModuleOptions, Rfc7807ModuleAsyncOptions, Rfc7807OptionsFactory, } from './interfaces';
|
|
4
|
+
export { ProblemDetailException, ProblemDetailParams, HttpProblemOptions, BadRequestProblem, UnauthorizedProblem, ForbiddenProblem, NotFoundProblem, ConflictProblem, UnprocessableEntityProblem, TooManyRequestsProblem, InternalServerErrorProblem, } from './exceptions';
|
|
5
|
+
export { JsonProblemDetailSerializer } from './serializers';
|
|
6
|
+
export { Rfc7807ExceptionFilter } from './filters';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAGjD,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAGlE,OAAO,EACL,cAAc,EACd,wBAAwB,EACxB,oBAAoB,EACpB,yBAAyB,EACzB,qBAAqB,GACtB,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,sBAAsB,EACtB,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,0BAA0B,EAC1B,sBAAsB,EACtB,0BAA0B,GAC3B,MAAM,cAAc,CAAC;AAGtB,OAAO,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAG5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Rfc7807ExceptionFilter = exports.JsonProblemDetailSerializer = exports.InternalServerErrorProblem = exports.TooManyRequestsProblem = exports.UnprocessableEntityProblem = exports.ConflictProblem = exports.NotFoundProblem = exports.ForbiddenProblem = exports.UnauthorizedProblem = exports.BadRequestProblem = exports.ProblemDetailException = exports.RFC7807_SERIALIZER = exports.RFC7807_OPTIONS = exports.Rfc7807Module = void 0;
|
|
4
|
+
var rfc7807_module_1 = require("./rfc7807.module");
|
|
5
|
+
Object.defineProperty(exports, "Rfc7807Module", { enumerable: true, get: function () { return rfc7807_module_1.Rfc7807Module; } });
|
|
6
|
+
var constants_1 = require("./constants");
|
|
7
|
+
Object.defineProperty(exports, "RFC7807_OPTIONS", { enumerable: true, get: function () { return constants_1.RFC7807_OPTIONS; } });
|
|
8
|
+
Object.defineProperty(exports, "RFC7807_SERIALIZER", { enumerable: true, get: function () { return constants_1.RFC7807_SERIALIZER; } });
|
|
9
|
+
var exceptions_1 = require("./exceptions");
|
|
10
|
+
Object.defineProperty(exports, "ProblemDetailException", { enumerable: true, get: function () { return exceptions_1.ProblemDetailException; } });
|
|
11
|
+
Object.defineProperty(exports, "BadRequestProblem", { enumerable: true, get: function () { return exceptions_1.BadRequestProblem; } });
|
|
12
|
+
Object.defineProperty(exports, "UnauthorizedProblem", { enumerable: true, get: function () { return exceptions_1.UnauthorizedProblem; } });
|
|
13
|
+
Object.defineProperty(exports, "ForbiddenProblem", { enumerable: true, get: function () { return exceptions_1.ForbiddenProblem; } });
|
|
14
|
+
Object.defineProperty(exports, "NotFoundProblem", { enumerable: true, get: function () { return exceptions_1.NotFoundProblem; } });
|
|
15
|
+
Object.defineProperty(exports, "ConflictProblem", { enumerable: true, get: function () { return exceptions_1.ConflictProblem; } });
|
|
16
|
+
Object.defineProperty(exports, "UnprocessableEntityProblem", { enumerable: true, get: function () { return exceptions_1.UnprocessableEntityProblem; } });
|
|
17
|
+
Object.defineProperty(exports, "TooManyRequestsProblem", { enumerable: true, get: function () { return exceptions_1.TooManyRequestsProblem; } });
|
|
18
|
+
Object.defineProperty(exports, "InternalServerErrorProblem", { enumerable: true, get: function () { return exceptions_1.InternalServerErrorProblem; } });
|
|
19
|
+
var serializers_1 = require("./serializers");
|
|
20
|
+
Object.defineProperty(exports, "JsonProblemDetailSerializer", { enumerable: true, get: function () { return serializers_1.JsonProblemDetailSerializer; } });
|
|
21
|
+
var filters_1 = require("./filters");
|
|
22
|
+
Object.defineProperty(exports, "Rfc7807ExceptionFilter", { enumerable: true, get: function () { return filters_1.Rfc7807ExceptionFilter; } });
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAWA,mDAAiD;AAAxC,+GAAA,aAAa,OAAA;AAGtB,yCAAkE;AAAzD,4GAAA,eAAe,OAAA;AAAE,+GAAA,kBAAkB,OAAA;AAY5C,2CAYsB;AAXpB,oHAAA,sBAAsB,OAAA;AAGtB,+GAAA,iBAAiB,OAAA;AACjB,iHAAA,mBAAmB,OAAA;AACnB,8GAAA,gBAAgB,OAAA;AAChB,6GAAA,eAAe,OAAA;AACf,6GAAA,eAAe,OAAA;AACf,wHAAA,0BAA0B,OAAA;AAC1B,oHAAA,sBAAsB,OAAA;AACtB,wHAAA,0BAA0B,OAAA;AAI5B,6CAA4D;AAAnD,0HAAA,2BAA2B,OAAA;AAGpC,qCAAmD;AAA1C,iHAAA,sBAAsB,OAAA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { IProblemDetail } from './problem-detail.interface';
|
|
2
|
+
export { IProblemDetailSerializer } from './problem-detail-serializer.interface';
|
|
3
|
+
export { Rfc7807ModuleOptions, Rfc7807ModuleAsyncOptions, Rfc7807OptionsFactory, } from './rfc7807-module-options.interface';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/interfaces/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,wBAAwB,EAAE,MAAM,uCAAuC,CAAC;AACjF,OAAO,EACL,oBAAoB,EACpB,yBAAyB,EACzB,qBAAqB,GACtB,MAAM,oCAAoC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/interfaces/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"problem-detail-serializer.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/problem-detail-serializer.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAU5D,MAAM,WAAW,wBAAwB;IAMvC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAQ7B,SAAS,CAAC,OAAO,EAAE,cAAc,GAAG,MAAM,CAAC;CAC5C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"problem-detail-serializer.interface.js","sourceRoot":"","sources":["../../src/interfaces/problem-detail-serializer.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"problem-detail.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/problem-detail.interface.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,cAAc;IAO7B,IAAI,EAAE,MAAM,CAAC;IAOb,KAAK,EAAE,MAAM,CAAC;IAMd,MAAM,EAAE,MAAM,CAAC;IAMf,MAAM,CAAC,EAAE,MAAM,CAAC;IAOhB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAMlB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"problem-detail.interface.js","sourceRoot":"","sources":["../../src/interfaces/problem-detail.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ModuleMetadata, Type } from '@nestjs/common';
|
|
2
|
+
import { IProblemDetail } from './problem-detail.interface';
|
|
3
|
+
import { IProblemDetailSerializer } from './problem-detail-serializer.interface';
|
|
4
|
+
export interface Rfc7807ModuleOptions {
|
|
5
|
+
serializer?: IProblemDetailSerializer;
|
|
6
|
+
includeStackTrace?: boolean;
|
|
7
|
+
onProblem?: (problem: IProblemDetail, exception: Error) => void;
|
|
8
|
+
typeBaseUri?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface Rfc7807OptionsFactory {
|
|
11
|
+
createRfc7807Options(): Rfc7807ModuleOptions | Promise<Rfc7807ModuleOptions>;
|
|
12
|
+
}
|
|
13
|
+
export interface Rfc7807ModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
|
|
14
|
+
useFactory?: (...args: any[]) => Rfc7807ModuleOptions | Promise<Rfc7807ModuleOptions>;
|
|
15
|
+
inject?: any[];
|
|
16
|
+
useClass?: Type<Rfc7807OptionsFactory>;
|
|
17
|
+
useExisting?: Type<Rfc7807OptionsFactory>;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=rfc7807-module-options.interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rfc7807-module-options.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/rfc7807-module-options.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,wBAAwB,EAAE,MAAM,uCAAuC,CAAC;AAKjF,MAAM,WAAW,oBAAoB;IAKnC,UAAU,CAAC,EAAE,wBAAwB,CAAC;IAOtC,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAO5B,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,KAAK,KAAK,IAAI,CAAC;IAOhE,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAKD,MAAM,WAAW,qBAAqB;IACpC,oBAAoB,IAAI,oBAAoB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;CAC9E;AAMD,MAAM,WAAW,yBAA0B,SAAQ,IAAI,CACrD,cAAc,EACd,SAAS,CACV;IAIC,UAAU,CAAC,EAAE,CACX,GAAG,IAAI,EAAE,GAAG,EAAE,KACX,oBAAoB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAK1D,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC;IAKf,QAAQ,CAAC,EAAE,IAAI,CAAC,qBAAqB,CAAC,CAAC;IAKvC,WAAW,CAAC,EAAE,IAAI,CAAC,qBAAqB,CAAC,CAAC;CAC3C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rfc7807-module-options.interface.js","sourceRoot":"","sources":["../../src/interfaces/rfc7807-module-options.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { Rfc7807ModuleOptions, Rfc7807ModuleAsyncOptions } from './interfaces/rfc7807-module-options.interface';
|
|
3
|
+
export declare class Rfc7807Module {
|
|
4
|
+
static forRoot(options?: Rfc7807ModuleOptions): DynamicModule;
|
|
5
|
+
static forRootAsync(asyncOptions: Rfc7807ModuleAsyncOptions): DynamicModule;
|
|
6
|
+
private static createAsyncProviders;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=rfc7807.module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rfc7807.module.d.ts","sourceRoot":"","sources":["../src/rfc7807.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAA4B,MAAM,gBAAgB,CAAC;AAKzE,OAAO,EACL,oBAAoB,EACpB,yBAAyB,EAE1B,MAAM,+CAA+C,CAAC;AA0BvD,qBAEa,aAAa;IAOxB,MAAM,CAAC,OAAO,CAAC,OAAO,GAAE,oBAAyB,GAAG,aAAa;IAgCjE,MAAM,CAAC,YAAY,CAAC,YAAY,EAAE,yBAAyB,GAAG,aAAa;IA0B3E,OAAO,CAAC,MAAM,CAAC,oBAAoB;CA8CpC"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var Rfc7807Module_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.Rfc7807Module = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const core_1 = require("@nestjs/core");
|
|
13
|
+
const constants_1 = require("./constants");
|
|
14
|
+
const rfc7807_exception_filter_1 = require("./filters/rfc7807-exception.filter");
|
|
15
|
+
const json_problem_detail_serializer_1 = require("./serializers/json-problem-detail.serializer");
|
|
16
|
+
let Rfc7807Module = Rfc7807Module_1 = class Rfc7807Module {
|
|
17
|
+
static forRoot(options = {}) {
|
|
18
|
+
const serializer = options.serializer ?? new json_problem_detail_serializer_1.JsonProblemDetailSerializer();
|
|
19
|
+
const providers = [
|
|
20
|
+
{
|
|
21
|
+
provide: constants_1.RFC7807_OPTIONS,
|
|
22
|
+
useValue: options,
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
provide: constants_1.RFC7807_SERIALIZER,
|
|
26
|
+
useValue: serializer,
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
provide: core_1.APP_FILTER,
|
|
30
|
+
useClass: rfc7807_exception_filter_1.Rfc7807ExceptionFilter,
|
|
31
|
+
},
|
|
32
|
+
];
|
|
33
|
+
return {
|
|
34
|
+
module: Rfc7807Module_1,
|
|
35
|
+
providers,
|
|
36
|
+
exports: [constants_1.RFC7807_OPTIONS, constants_1.RFC7807_SERIALIZER],
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
static forRootAsync(asyncOptions) {
|
|
40
|
+
const providers = [
|
|
41
|
+
...Rfc7807Module_1.createAsyncProviders(asyncOptions),
|
|
42
|
+
{
|
|
43
|
+
provide: constants_1.RFC7807_SERIALIZER,
|
|
44
|
+
useFactory: (options) => options.serializer ?? new json_problem_detail_serializer_1.JsonProblemDetailSerializer(),
|
|
45
|
+
inject: [constants_1.RFC7807_OPTIONS],
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
provide: core_1.APP_FILTER,
|
|
49
|
+
useClass: rfc7807_exception_filter_1.Rfc7807ExceptionFilter,
|
|
50
|
+
},
|
|
51
|
+
];
|
|
52
|
+
return {
|
|
53
|
+
module: Rfc7807Module_1,
|
|
54
|
+
imports: asyncOptions.imports ?? [],
|
|
55
|
+
providers,
|
|
56
|
+
exports: [constants_1.RFC7807_OPTIONS, constants_1.RFC7807_SERIALIZER],
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
static createAsyncProviders(asyncOptions) {
|
|
60
|
+
if (asyncOptions.useFactory) {
|
|
61
|
+
return [
|
|
62
|
+
{
|
|
63
|
+
provide: constants_1.RFC7807_OPTIONS,
|
|
64
|
+
useFactory: asyncOptions.useFactory,
|
|
65
|
+
inject: asyncOptions.inject ?? [],
|
|
66
|
+
},
|
|
67
|
+
];
|
|
68
|
+
}
|
|
69
|
+
if (asyncOptions.useClass) {
|
|
70
|
+
return [
|
|
71
|
+
{
|
|
72
|
+
provide: asyncOptions.useClass,
|
|
73
|
+
useClass: asyncOptions.useClass,
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
provide: constants_1.RFC7807_OPTIONS,
|
|
77
|
+
useFactory: (factory) => factory.createRfc7807Options(),
|
|
78
|
+
inject: [asyncOptions.useClass],
|
|
79
|
+
},
|
|
80
|
+
];
|
|
81
|
+
}
|
|
82
|
+
if (asyncOptions.useExisting) {
|
|
83
|
+
return [
|
|
84
|
+
{
|
|
85
|
+
provide: constants_1.RFC7807_OPTIONS,
|
|
86
|
+
useFactory: (factory) => factory.createRfc7807Options(),
|
|
87
|
+
inject: [asyncOptions.useExisting],
|
|
88
|
+
},
|
|
89
|
+
];
|
|
90
|
+
}
|
|
91
|
+
return [
|
|
92
|
+
{
|
|
93
|
+
provide: constants_1.RFC7807_OPTIONS,
|
|
94
|
+
useValue: {},
|
|
95
|
+
},
|
|
96
|
+
];
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
exports.Rfc7807Module = Rfc7807Module;
|
|
100
|
+
exports.Rfc7807Module = Rfc7807Module = Rfc7807Module_1 = __decorate([
|
|
101
|
+
(0, common_1.Global)(),
|
|
102
|
+
(0, common_1.Module)({})
|
|
103
|
+
], Rfc7807Module);
|
|
104
|
+
//# sourceMappingURL=rfc7807.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rfc7807.module.js","sourceRoot":"","sources":["../src/rfc7807.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAyE;AACzE,uCAA0C;AAE1C,2CAAkE;AAClE,iFAA4E;AAM5E,iGAA2F;AA2BpF,IAAM,aAAa,qBAAnB,MAAM,aAAa;IAOxB,MAAM,CAAC,OAAO,CAAC,UAAgC,EAAE;QAC/C,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,IAAI,4DAA2B,EAAE,CAAC;QAE3E,MAAM,SAAS,GAAe;YAC5B;gBACE,OAAO,EAAE,2BAAe;gBACxB,QAAQ,EAAE,OAAO;aAClB;YACD;gBACE,OAAO,EAAE,8BAAkB;gBAC3B,QAAQ,EAAE,UAAU;aACrB;YACD;gBACE,OAAO,EAAE,iBAAU;gBACnB,QAAQ,EAAE,iDAAsB;aACjC;SACF,CAAC;QAEF,OAAO;YACL,MAAM,EAAE,eAAa;YACrB,SAAS;YACT,OAAO,EAAE,CAAC,2BAAe,EAAE,8BAAkB,CAAC;SAC/C,CAAC;IACJ,CAAC;IASD,MAAM,CAAC,YAAY,CAAC,YAAuC;QACzD,MAAM,SAAS,GAAe;YAC5B,GAAG,eAAa,CAAC,oBAAoB,CAAC,YAAY,CAAC;YACnD;gBACE,OAAO,EAAE,8BAAkB;gBAC3B,UAAU,EAAE,CAAC,OAA6B,EAAE,EAAE,CAC5C,OAAO,CAAC,UAAU,IAAI,IAAI,4DAA2B,EAAE;gBACzD,MAAM,EAAE,CAAC,2BAAe,CAA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,GAAE;IACR,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,aAAa,CA+GzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/serializers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JsonProblemDetailSerializer = void 0;
|
|
4
|
+
var json_problem_detail_serializer_1 = require("./json-problem-detail.serializer");
|
|
5
|
+
Object.defineProperty(exports, "JsonProblemDetailSerializer", { enumerable: true, get: function () { return json_problem_detail_serializer_1.JsonProblemDetailSerializer; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/serializers/index.ts"],"names":[],"mappings":";;;AAAA,mFAA+E;AAAtE,6IAAA,2BAA2B,OAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { IProblemDetail } from '../interfaces/problem-detail.interface';
|
|
2
|
+
import { IProblemDetailSerializer } from '../interfaces/problem-detail-serializer.interface';
|
|
3
|
+
export declare class JsonProblemDetailSerializer implements IProblemDetailSerializer {
|
|
4
|
+
readonly contentType = "application/problem+json";
|
|
5
|
+
serialize(problem: IProblemDetail): string;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=json-problem-detail.serializer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-problem-detail.serializer.d.ts","sourceRoot":"","sources":["../../src/serializers/json-problem-detail.serializer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AACxE,OAAO,EAAE,wBAAwB,EAAE,MAAM,mDAAmD,CAAC;AAY7F,qBAAa,2BAA4B,YAAW,wBAAwB;IAC1E,SAAgB,WAAW,8BAA8B;IAYzD,SAAS,CAAC,OAAO,EAAE,cAAc,GAAG,MAAM;CAuB3C"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JsonProblemDetailSerializer = void 0;
|
|
4
|
+
class JsonProblemDetailSerializer {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.contentType = 'application/problem+json';
|
|
7
|
+
}
|
|
8
|
+
serialize(problem) {
|
|
9
|
+
const { type, title, status, detail, instance, ...extensions } = problem;
|
|
10
|
+
const ordered = { type, title, status };
|
|
11
|
+
if (detail !== undefined) {
|
|
12
|
+
ordered.detail = detail;
|
|
13
|
+
}
|
|
14
|
+
if (instance !== undefined) {
|
|
15
|
+
ordered.instance = instance;
|
|
16
|
+
}
|
|
17
|
+
for (const [key, value] of Object.entries(extensions)) {
|
|
18
|
+
if (value !== undefined) {
|
|
19
|
+
ordered[key] = value;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return JSON.stringify(ordered);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.JsonProblemDetailSerializer = JsonProblemDetailSerializer;
|
|
26
|
+
//# sourceMappingURL=json-problem-detail.serializer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-problem-detail.serializer.js","sourceRoot":"","sources":["../../src/serializers/json-problem-detail.serializer.ts"],"names":[],"mappings":";;;AAaA,MAAa,2BAA2B;IAAxC;QACkB,gBAAW,GAAG,0BAA0B,CAAC;IAmC3D,CAAC;IAvBC,SAAS,CAAC,OAAuB;QAC/B,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,UAAU,EAAE,GAAG,OAAO,CAAC;QAGzE,MAAM,OAAO,GAA4B,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;QAEjE,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACzB,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC;QAC1B,CAAC;QAED,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;YAC3B,OAAO,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAC9B,CAAC;QAGD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;YACtD,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACxB,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;YACvB,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IACjC,CAAC;CACF;AApCD,kEAoCC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@xavierdev25/rfc7807-errors",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "NestJS global exception filter implementing RFC 7807 Problem Details for HTTP APIs",
|
|
5
|
+
"author": "Xavier Montaño",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist/**/*"
|
|
11
|
+
],
|
|
12
|
+
"keywords": [
|
|
13
|
+
"nestjs",
|
|
14
|
+
"rfc7807",
|
|
15
|
+
"problem-details",
|
|
16
|
+
"exception-filter",
|
|
17
|
+
"error-handling",
|
|
18
|
+
"http-api",
|
|
19
|
+
"application/problem+json"
|
|
20
|
+
],
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "https://github.com/xavierdev25/nestjs-rfc7807-errors",
|
|
24
|
+
"directory": "libs/rfc7807-errors"
|
|
25
|
+
},
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "tsc -p tsconfig.build.json",
|
|
31
|
+
"test": "jest",
|
|
32
|
+
"test:watch": "jest --watch",
|
|
33
|
+
"test:cov": "jest --coverage",
|
|
34
|
+
"prepublishOnly": "pnpm build"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"@nestjs/common": "^10.0.0 || ^11.0.0",
|
|
38
|
+
"@nestjs/core": "^10.0.0 || ^11.0.0",
|
|
39
|
+
"rxjs": "^7.0.0"
|
|
40
|
+
},
|
|
41
|
+
"jest": {
|
|
42
|
+
"moduleFileExtensions": ["js", "json", "ts"],
|
|
43
|
+
"rootDir": "src",
|
|
44
|
+
"testRegex": ".*\\.spec\\.ts$",
|
|
45
|
+
"transform": {
|
|
46
|
+
"^.+\\.ts$": "ts-jest"
|
|
47
|
+
},
|
|
48
|
+
"collectCoverageFrom": [
|
|
49
|
+
"**/*.ts",
|
|
50
|
+
"!**/*.d.ts",
|
|
51
|
+
"!**/index.ts",
|
|
52
|
+
"!**/__tests__/**"
|
|
53
|
+
],
|
|
54
|
+
"coveragePathIgnorePatterns": [
|
|
55
|
+
"dist/",
|
|
56
|
+
"node_modules/",
|
|
57
|
+
".*\\.spec\\.ts$"
|
|
58
|
+
],
|
|
59
|
+
"coverageDirectory": "../coverage",
|
|
60
|
+
"coverageThreshold": {
|
|
61
|
+
"global": {
|
|
62
|
+
"branches": 90,
|
|
63
|
+
"functions": 90,
|
|
64
|
+
"lines": 90,
|
|
65
|
+
"statements": 90
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
"testEnvironment": "node"
|
|
69
|
+
}
|
|
70
|
+
}
|