-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Throw service error from query runner - Catch in resolver factories - Map to graphql errors --------- Co-authored-by: Charles Bochet <[email protected]>
- Loading branch information
1 parent
3ff2465
commit 3060eb4
Showing
17 changed files
with
276 additions
and
292 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
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
36 changes: 36 additions & 0 deletions
36
...workspace-query-runner/utils/workspace-query-runner-graphql-api-exception-handler.util.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,36 @@ | ||
import { | ||
WorkspaceQueryRunnerException, | ||
WorkspaceQueryRunnerExceptionCode, | ||
} from 'src/engine/api/graphql/workspace-query-runner/workspace-query-runner.exception'; | ||
import { | ||
ForbiddenError, | ||
InternalServerError, | ||
NotFoundError, | ||
TimeoutError, | ||
UserInputError, | ||
} from 'src/engine/core-modules/graphql/utils/graphql-errors.util'; | ||
|
||
export const workspaceQueryRunnerGraphqlApiExceptionHandler = ( | ||
error: Error, | ||
) => { | ||
if (error instanceof WorkspaceQueryRunnerException) { | ||
switch (error.code) { | ||
case WorkspaceQueryRunnerExceptionCode.DATA_NOT_FOUND: | ||
throw new NotFoundError(error.message); | ||
case WorkspaceQueryRunnerExceptionCode.INVALID_QUERY_INPUT: | ||
throw new UserInputError(error.message); | ||
case WorkspaceQueryRunnerExceptionCode.QUERY_VIOLATES_UNIQUE_CONSTRAINT: | ||
case WorkspaceQueryRunnerExceptionCode.QUERY_VIOLATES_FOREIGN_KEY_CONSTRAINT: | ||
case WorkspaceQueryRunnerExceptionCode.TOO_MANY_ROWS_AFFECTED: | ||
case WorkspaceQueryRunnerExceptionCode.NO_ROWS_AFFECTED: | ||
throw new ForbiddenError(error.message); | ||
case WorkspaceQueryRunnerExceptionCode.QUERY_TIMEOUT: | ||
throw new TimeoutError(error.message); | ||
case WorkspaceQueryRunnerExceptionCode.INTERNAL_SERVER_ERROR: | ||
default: | ||
throw new InternalServerError(error.message); | ||
} | ||
} | ||
|
||
throw error; | ||
}; |
19 changes: 19 additions & 0 deletions
19
...-server/src/engine/api/graphql/workspace-query-runner/workspace-query-runner.exception.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,19 @@ | ||
import { CustomException } from 'src/utils/custom-exception'; | ||
|
||
export class WorkspaceQueryRunnerException extends CustomException { | ||
code: WorkspaceQueryRunnerExceptionCode; | ||
constructor(message: string, code: WorkspaceQueryRunnerExceptionCode) { | ||
super(message, code); | ||
} | ||
} | ||
|
||
export enum WorkspaceQueryRunnerExceptionCode { | ||
INVALID_QUERY_INPUT = 'INVALID_FIELD_INPUT', | ||
DATA_NOT_FOUND = 'DATA_NOT_FOUND', | ||
QUERY_TIMEOUT = 'QUERY_TIMEOUT', | ||
QUERY_VIOLATES_UNIQUE_CONSTRAINT = 'QUERY_VIOLATES_UNIQUE_CONSTRAINT', | ||
QUERY_VIOLATES_FOREIGN_KEY_CONSTRAINT = 'QUERY_VIOLATES_FOREIGN_KEY_CONSTRAINT', | ||
TOO_MANY_ROWS_AFFECTED = 'TOO_MANY_ROWS_AFFECTED', | ||
NO_ROWS_AFFECTED = 'NO_ROWS_AFFECTED', | ||
INTERNAL_SERVER_ERROR = 'INTERNAL_SERVER_ERROR', | ||
} |
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
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
Oops, something went wrong.