-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
refactor(server): server errors #5741
Conversation
Your org has enabled the Graphite merge queue for merging into canaryYou must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link. You can enable merging using labels in your Graphite merge queue settings. |
Current dependencies on/for this PR:
This stack of pull requests is managed by Graphite. |
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## canary #5741 +/- ##
==========================================
+ Coverage 64.47% 64.64% +0.16%
==========================================
Files 339 343 +4
Lines 19242 19303 +61
Branches 1632 1644 +12
==========================================
+ Hits 12407 12478 +71
+ Misses 6619 6609 -10
Partials 216 216
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
e4ab38a
to
d4bb81e
Compare
a0e2e6e
to
ea337be
Compare
8ee2d61
to
f08469a
Compare
5f08d1b
to
e8853d2
Compare
Merge activity
|
standardize the error raising in both GraphQL Resolvers and Controllers. Now, All user aware errors should be throwed with `HttpException`'s variants, for example `NotFoundException`. > Directly throwing `GraphQLError` are forbidden. The GraphQL errorFormatter will handle it automatically and set `code`, `status` in error extensions. At the same time, the frontend `GraphQLError` should be imported from `@affine/graphql`, which introduce a better error extensions type. ---- controller example: ```js @get('/docs/${id}') doc() { // ... // imported from '@nestjs/common' throw new NotFoundException('Doc is not found.'); // ... } ``` the above will response as: ``` status: 404 Not Found { "message": "Doc is not found.", "statusCode": 404, "error": "Not Found" } ``` resolver example: ```js @mutation() invite() { // ... throw new PayloadTooLargeException('Workspace seats is full.') // ... } ``` the above will response as: ``` status: 200 Ok { "data": null, "errors": [ { "message": "Workspace seats is full.", "extensions": { "code": 404, "status": "Not Found" } } ] } ``` for frontend GraphQLError user-friend, a helper function introduced: ```js import { findGraphQLError } from '@affine/graphql' fetch(query) .catch(errOrArr => { const e = findGraphQLError(errOrArr, e => e.extensions.code === 404) if (e) { // handle } }) ```
e8853d2
to
26db1d4
Compare
standardize the error raising in both GraphQL Resolvers and Controllers.
Now, All user aware errors should be throwed with
HttpException
's variants, for exampleNotFoundException
.At the same time, the frontend
GraphQLError
should be imported from@affine/graphql
, which introduce a better error extensions type.controller example:
the above will response as:
resolver example:
the above will response as:
for frontend GraphQLError user-friend, a helper function introduced: