@nest-yalc-2/errors 2.2.2 → 2.2.3
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/package.json +11 -11
- package/src/__tests__/database-exception.filter.spec.ts +71 -71
- package/src/__tests__/http-exception.filter.spec.ts +182 -182
- package/src/__tests__/system-exception.filter.spec.ts +39 -39
- package/src/__tests__/validation-exception.filter.spec.ts +31 -31
- package/src/filters/database-exception.filter.ts +45 -45
- package/src/filters/http-exception.filter.ts +144 -144
- package/src/filters/index.ts +6 -6
- package/src/filters/system-exception.filter.ts +13 -13
- package/src/filters/validation-exception.filter.ts +26 -26
- package/src/index.ts +8 -8
- package/src/__tests__/default.error.spec.ts +0 -529
- package/src/__tests__/error.helper.spec.ts +0 -23
- package/src/__tests__/errors.enum.spec.ts +0 -32
- package/src/__tests__/http-status-code-to-errors.spec.ts +0 -26
- package/src/__tests__/input-validation.error.spec.ts +0 -27
- package/src/__tests__/login.error.spec.ts +0 -23
- package/src/__tests__/result.error.spec.ts +0 -47
- package/src/__tests__/verification.error.spec.ts +0 -28
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from '@jest/globals';
|
|
2
|
-
import { tryCatch, tryCatchAsync } from '../result.error.js';
|
|
3
|
-
import { DefaultError } from '../default.error.js';
|
|
4
|
-
|
|
5
|
-
describe('ResultError', () => {
|
|
6
|
-
it('should handle sync success', () => {
|
|
7
|
-
const result = tryCatch(() => 'success');
|
|
8
|
-
if (result.isErr()) {
|
|
9
|
-
expect(true).toBe(false);
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
expect(result.isOk()).toBe(true);
|
|
13
|
-
expect(result.value).toBe('success');
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('should handle sync error', () => {
|
|
17
|
-
const result = tryCatch(() => {
|
|
18
|
-
throw new Error('error');
|
|
19
|
-
});
|
|
20
|
-
if (result.isOk()) {
|
|
21
|
-
expect(true).toBe(false);
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
expect(result.error).toBeInstanceOf(DefaultError);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('should handle async success', async () => {
|
|
28
|
-
const result = await tryCatchAsync(async () => 'success');
|
|
29
|
-
if (result.isErr()) {
|
|
30
|
-
expect(true).toBe(false);
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
expect(result.isOk()).toBe(true);
|
|
34
|
-
expect(result.value).toBe('success');
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('should handle async error', async () => {
|
|
38
|
-
const result = await tryCatchAsync(async () => {
|
|
39
|
-
throw new Error('error');
|
|
40
|
-
});
|
|
41
|
-
if (result.isOk()) {
|
|
42
|
-
expect(true).toBe(false);
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
expect(result.error).toBeInstanceOf(DefaultError);
|
|
46
|
-
});
|
|
47
|
-
});
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { expect, describe, it } from '@jest/globals';
|
|
2
|
-
import {
|
|
3
|
-
getHttpStatusDescription,
|
|
4
|
-
HttpStatusCodes,
|
|
5
|
-
} from '@node-yalc/utils/http.helper.js';
|
|
6
|
-
import { HttpException } from '@nestjs/common';
|
|
7
|
-
import { AdditionalVerificationNeededError } from '../index.js';
|
|
8
|
-
|
|
9
|
-
describe('Verification error', () => {
|
|
10
|
-
const error = new AdditionalVerificationNeededError();
|
|
11
|
-
|
|
12
|
-
it('should be defined', () => {
|
|
13
|
-
expect(error).toBeDefined();
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('should have the correct message and code', () => {
|
|
17
|
-
expect(error.description).toEqual(
|
|
18
|
-
getHttpStatusDescription(HttpStatusCodes.UnavailableForLegalReasons),
|
|
19
|
-
);
|
|
20
|
-
expect(error.getStatus()).toEqual(
|
|
21
|
-
HttpStatusCodes.UnavailableForLegalReasons,
|
|
22
|
-
);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('should be an instance of HttpException', () => {
|
|
26
|
-
expect(error).toBeInstanceOf(HttpException);
|
|
27
|
-
});
|
|
28
|
-
});
|