-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UISACQCOMP-219 Add typings for the ACQ 'ResponseErrorsContainer' utils (
#66) * UISACQCOMP-219 Add typings for the ACQ 'ResponseErrorsContainer' utils * add 'acq-components' typings to exports
- Loading branch information
1 parent
c4aea45
commit e3bc064
Showing
6 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
acq-components/lib/utils/errorHandling/ResponseErrorContainer.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
export interface ResponseErrorParameter { | ||
key: string; | ||
value: string; | ||
} | ||
|
||
export interface ResponseError { | ||
message?: string; | ||
code?: string; | ||
type?: string; | ||
parameters?: ResponseErrorParameter[]; | ||
} | ||
|
||
/** | ||
* @class | ||
* @description Container for response error. | ||
*/ | ||
export class ResponseErrorContainer { | ||
constructor(error?: ResponseError); | ||
|
||
/** | ||
* @description Get the error message. | ||
*/ | ||
get message(): string | undefined; | ||
|
||
/** | ||
* @description Get the error code. | ||
*/ | ||
get code(): string | undefined; | ||
|
||
/** | ||
* @description Get the error type. | ||
*/ | ||
get type(): string | undefined; | ||
|
||
/** | ||
* @description Get the error parameters. | ||
*/ | ||
get parameters(): ResponseErrorParameter[] | undefined; | ||
|
||
/** | ||
* @description Get the error parameters as a map. | ||
*/ | ||
getParameters(): Map<string, ResponseErrorParameter>; | ||
|
||
/** | ||
* @description Get a specific parameter by its key. | ||
*/ | ||
getParameter(key: string): string | undefined; | ||
} |
75 changes: 75 additions & 0 deletions
75
acq-components/lib/utils/errorHandling/ResponseErrorsContainer.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { ResponseErrorContainer } from './ResponseErrorContainer'; | ||
|
||
export interface ResponseErrorsContainerBody { | ||
errors: unknown[]; | ||
// eslint-disable-next-line camelcase | ||
total_records: number; | ||
} | ||
|
||
export interface ErrorHandlingStrategy { | ||
handle(errors: ResponseErrorsContainer): void; | ||
} | ||
|
||
/** | ||
* @class | ||
* @description Container for response errors. | ||
*/ | ||
export class ResponseErrorsContainer { | ||
originalResponseBody: unknown; | ||
originalResponse?: Response; | ||
totalRecords: number; | ||
errorsMap: Map<string, ResponseErrorContainer>; | ||
|
||
/** | ||
* @private | ||
* @description Create a new instance of ResponseErrorsContainer. Instances are supposed to be created via the static create method. | ||
*/ | ||
private constructor(responseBody: ResponseErrorsContainerBody, response?: Response); | ||
|
||
/** | ||
* @static | ||
* @description Create a new instance of ResponseErrorsContainer. | ||
*/ | ||
static create(response: Response): Promise<{ handler: ResponseErrorsContainer }>; | ||
|
||
/** | ||
* @description Handle the errors using a given strategy. | ||
*/ | ||
handle(strategy: ErrorHandlingStrategy): any | Promise<any>; | ||
|
||
/** | ||
* @description Get the status of the response. | ||
*/ | ||
get status(): number | undefined; | ||
|
||
/** | ||
* @description Get an array of error messages. | ||
*/ | ||
get errorMessages(): Array<string | undefined>; | ||
|
||
/** | ||
* @description Get an array of error codes. | ||
*/ | ||
get errorCodes(): Array<string | undefined>; | ||
|
||
/** | ||
* @description Get all errors as an array. | ||
*/ | ||
get errors(): ResponseErrorContainer[]; | ||
|
||
/** | ||
* @description Get all errors as a map. | ||
*/ | ||
getErrors(): Map<string, ResponseErrorContainer>; | ||
|
||
/** | ||
* @description Get a specific error by its code or the first error if no code is provided. | ||
*/ | ||
getError(code?: string): ResponseErrorContainer; | ||
|
||
/** | ||
* @private | ||
* @description Normalize an unknown error into a structured ResponseErrorContainer. | ||
*/ | ||
private getStructuredError(error: unknown): ResponseErrorContainer; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { ResponseErrorsContainer } from './ResponseErrorsContainer'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters