Skip to content

Commit 86a7af8

Browse files
authored
Merge pull request #6 from Alpha018/fix/module
refactor: reorganize unleash error handling and enhance decorator functionality
2 parents 3b96362 + 3aa29d0 commit 86a7af8

File tree

15 files changed

+62
-40
lines changed

15 files changed

+62
-40
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"author": "Tomás Alegre <tomas.sa467@gmail.com>",
66
"readmeFilename": "README.md",
77
"main": "dist/index.js",
8+
"types": "dist/index.d.ts",
89
"license": "MIT",
910
"engines": {
1011
"node": ">=20"
File renamed without changes.
File renamed without changes.

src/error/exceptions/code/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './unleash.code';
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
export enum UnleashErrorCode {
2+
STRATEGY_INVALID_PARAMETER = 'STRATEGY_INVALID_PARAMETER',
3+
STRATEGY_MISSING_PARAMETER = 'STRATEGY_MISSING_PARAMETER',
24
UNEXPECTED_UNLEASH_ERROR = 'UNEXPECTED_UNLEASH_ERROR',
35
NOT_FOUND_UNLEASH_ERROR = 'NOT_FOUND_UNLEASH_ERROR',
46
}

src/error/exceptions/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from './base.exception';
2+
export * from './provider';
3+
export * from './code';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './unleash.exceptions';

src/unleash/error-handler/exceptions/provider/unleash.exceptions.spec.ts renamed to src/error/exceptions/provider/unleash.exceptions.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { HttpStatus } from '@nestjs/common';
22

33
import { UnexpectedUnleashException, NotFoundUnleashException } from './unleash.exceptions';
4-
import { UnleashErrorCode } from '../code/unleash.code';
4+
import { UnleashErrorCode } from '../code';
55

66
describe('Unleash Exceptions', () => {
77
describe('UnexpectedUnleashException', () => {

src/unleash/error-handler/exceptions/provider/unleash.exceptions.ts renamed to src/error/exceptions/provider/unleash.exceptions.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { HttpStatus } from '@nestjs/common';
22

3-
import { UnleashErrorCode } from '../code/unleash.code';
43
import { BaseException } from '../base.exception';
4+
import { UnleashErrorCode } from '../code';
55

66
/**
77
* Base exception for Unleash-related errors.
@@ -17,6 +17,24 @@ export class UnexpectedUnleashException extends UnleashException {
1717
static override readonly status = HttpStatus.INTERNAL_SERVER_ERROR;
1818
}
1919

20+
/**
21+
* Represents an error where a strategy parameter is missing.
22+
*/
23+
export class StrategyMissingParameterException extends UnleashException {
24+
static override readonly code = UnleashErrorCode.STRATEGY_MISSING_PARAMETER;
25+
static override readonly message = 'Strategy parameter is missing';
26+
static override readonly status = HttpStatus.BAD_REQUEST;
27+
}
28+
29+
/**
30+
* Represents an error where a strategy parameter is invalid.
31+
*/
32+
export class StrategyInvalidParameterException extends UnleashException {
33+
static override readonly code = UnleashErrorCode.STRATEGY_INVALID_PARAMETER;
34+
static override readonly message = 'Strategy parameter is invalid';
35+
static override readonly status = HttpStatus.BAD_REQUEST;
36+
}
37+
2038
/**
2139
* Represents an error where a requested feature was not found in Unleash.
2240
*/

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export * from './unleash/decorators/unleash.decorator';
33
export * from './unleash/constant/unleash.constant';
44
export * from './unleash/unleash-client.module';
55
export * from './unleash/guards/unleash.guard';
6+
export * from './error/exceptions';

0 commit comments

Comments
 (0)