-
Notifications
You must be signed in to change notification settings - Fork 0
[LOCKLITE-104] Refactor error handling #64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
f678673
refactor: catch error in handleApiRequest
vbetsch fa8d1a7
refactor: move handleApiRequest in api folder
vbetsch 64447ff
refactor: re-create errors architecture
vbetsch b7c1b4c
refactor: create BusinessError
vbetsch 73ac171
refactor: handle BusinessError in handleApiRequest
vbetsch 98cba0c
fix: HttpErrorDto api doc
vbetsch 32d8e73
refactor: Move request service to services folder
vbetsch f9cb3ac
feat: handle BusinessError in LockliteApiRequestService
vbetsch fe5bee9
refactor: Move abstract errors in shared module
vbetsch 4698cd3
refactor: Use HttpError & BusinessError in frontend
vbetsch 6570827
refactor: Add toString methods in errors
vbetsch f01581f
fix: toString methods in errors
vbetsch 742621e
refactor: LockliteApiRequestService - create handleNoDataCase
vbetsch 0c286c6
refactor: LockliteApiRequestService - create _errorMessage
vbetsch 812b398
refactor: LockliteApiRequestService - create _parseData & _handlePars…
vbetsch ceaa870
fix: LockliteApiRequestService - create _parseData & _handleParseError
vbetsch 0201167
refactor: LockliteApiRequestService - create _handleNoData
vbetsch af559b2
refactor: LockliteApiRequestService - rename methods
vbetsch 10c56cf
refactor: Request services - move errorMessage in abstract
vbetsch 203b1ce
refactor: Request services - create _handleResponseNotOk
vbetsch db38e4d
fix: Request services - create _handleResponseNotOk
vbetsch 9928a1c
fix: Request services - rename _fetch to _request
vbetsch c59dd3e
fix: Request services - create _fetch
vbetsch 94d6b93
fix: Request services - protected naming
vbetsch 4bc23cf
refactor: move VaultAlreadyExistsError in vaults folder
vbetsch 5f6e1d4
feat: create VaultLabelTooLongError
vbetsch de5393b
fix: create BusinessErrorCodeEnumDto.VAULT_LABEL_TOO_LONG
vbetsch 4a2c92a
fix: add VaultAlreadyExistsError in api doc
vbetsch 5eb1d89
fix: tests of handleApiRequest
vbetsch 2a6ca27
refactor: move http error test
vbetsch 3775a60
refactor: move handle-api-request.test.ts in api folder
vbetsch 0efaabc
fix: move request.service.test.ts in services folder
vbetsch 4c27de3
fix: Type error: Variable 'vaultCreated' is used before being assigned.
vbetsch a4d8021
fix: use uri instead of url
vbetsch e908e2b
fix: typo
vbetsch a4687bc
fix: Property 'data' does not exist on type 'HttpResponseDto<Data>'
vbetsch 5295e4b
chore(linter): add @typescript-eslint/no-use-before-define & @typescr…
vbetsch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
src/modules/api/errors/business/vaults/vault-already-exists.error.ts
This file contains hidden or 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,13 @@ | ||
| import { StatusCodes } from 'http-status-codes'; | ||
| import { BusinessError } from '@shared/errors/business-error'; | ||
| import { BusinessErrorCodeEnumDto } from '@shared/dto/output/errors/business-error-code.enum.dto'; | ||
|
|
||
| export class VaultAlreadyExistsError extends BusinessError { | ||
| public constructor(label: string) { | ||
| super( | ||
| `Vault with label '${label}' already exists`, | ||
| StatusCodes.CONFLICT, | ||
| BusinessErrorCodeEnumDto.VAULT_ALREADY_EXISTS | ||
| ); | ||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
src/modules/api/errors/business/vaults/vault-label-too-long.error.ts
This file contains hidden or 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,13 @@ | ||
| import { StatusCodes } from 'http-status-codes'; | ||
| import { BusinessError } from '@shared/errors/business-error'; | ||
| import { BusinessErrorCodeEnumDto } from '@shared/dto/output/errors/business-error-code.enum.dto'; | ||
|
|
||
| export class VaultLabelTooLongError extends BusinessError { | ||
| public constructor() { | ||
| super( | ||
| `The vault label must not exceed 255 characters`, | ||
| StatusCodes.UNPROCESSABLE_ENTITY, | ||
| BusinessErrorCodeEnumDto.VAULT_LABEL_TOO_LONG | ||
| ); | ||
| } | ||
| } |
2 changes: 1 addition & 1 deletion
2
...dules/api/errors/internal-server.error.ts → .../api/errors/http/internal-server.error.ts
This file contains hidden or 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
2 changes: 1 addition & 1 deletion
2
...rors/prisma/invalid-request-data.error.ts → ...http/prisma/invalid-request-data.error.ts
This file contains hidden or 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
2 changes: 1 addition & 1 deletion
2
.../prisma/requested-value-too-long.error.ts → .../prisma/requested-value-too-long.error.ts
This file contains hidden or 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
2 changes: 1 addition & 1 deletion
2
...s/prisma/resource-already-exists.error.ts → ...p/prisma/resource-already-exists.error.ts
This file contains hidden or 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
2 changes: 1 addition & 1 deletion
2
...errors/prisma/resource-not-found.error.ts → ...s/http/prisma/resource-not-found.error.ts
This file contains hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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
4 changes: 4 additions & 0 deletions
4
src/modules/shared/dto/output/errors/business-error-code.enum.dto.ts
This file contains hidden or 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,4 @@ | ||
| export enum BusinessErrorCodeEnumDto { | ||
| VAULT_ALREADY_EXISTS = 'L-409-VAE', | ||
| VAULT_LABEL_TOO_LONG = 'L-422-VLTL', | ||
| } |
This file contains hidden or 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 hidden or 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,20 @@ | ||
| import { HttpError } from '@shared/errors/http-error'; | ||
| import type { BusinessErrorCodeEnumDto } from '@shared/dto/output/errors/business-error-code.enum.dto'; | ||
|
|
||
| export class BusinessError extends HttpError { | ||
| public readonly code: BusinessErrorCodeEnumDto; | ||
|
|
||
| public constructor( | ||
| message: string, | ||
vbetsch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| status: number, | ||
| code: BusinessErrorCodeEnumDto | ||
| ) { | ||
| super(message, status); | ||
| this.code = code; | ||
| this.name = this.constructor.name; | ||
| } | ||
|
|
||
| public override toString(): string { | ||
| return `[${this.code}] ${this.message}`; | ||
| } | ||
| } | ||
This file contains hidden or 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,13 @@ | ||
| export class HttpError extends Error { | ||
| public readonly status: number; | ||
|
|
||
| public constructor(message: string, status: number) { | ||
vbetsch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| super(message); | ||
| this.status = status; | ||
| this.name = this.constructor.name; | ||
| } | ||
|
|
||
| public override toString(): string { | ||
| return `(${this.status}) ${this.message}`; | ||
| } | ||
| } | ||
File renamed without changes.
This file contains hidden or 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,3 @@ | ||
| import type { SharedChildrenProps } from '@shared/props/SharedChildrenProps'; | ||
|
|
||
| export type SharedLayoutProps = SharedChildrenProps; |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.