0
0
GraphQLquery~10 mins

Custom error extensions in GraphQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add a custom error extension in a GraphQL error.

GraphQL
throw new GraphQLError('Invalid input', { extensions: { [1]: 'BAD_USER_INPUT' } });
Drag options to blanks, or click blank then click option'
Astatus
Bmessage
Ccode
Derror
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'message' instead of 'code' inside extensions.
Forgetting to put the custom code inside the extensions object.
2fill in blank
medium

Complete the code to include a custom error extension with a numeric HTTP status code.

GraphQL
throw new GraphQLError('Unauthorized', { extensions: { code: 'UNAUTHENTICATED', [1]: 401 } });
Drag options to blanks, or click blank then click option'
AstatusCode
BhttpStatus
CerrorCode
Dstatus
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'statusCode' which is less common in GraphQL error extensions.
Using 'errorCode' which is usually a string code, not a number.
3fill in blank
hard

Fix the error in the code to correctly add a custom error extension with a reason string.

GraphQL
throw new GraphQLError('Failed', { extensions: { code: 'FAILURE', reason [1] 'Timeout' } });
Drag options to blanks, or click blank then click option'
A=
B:
C=>
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of ':' in object literals.
Using '=>' which is for arrow functions, not object properties.
4fill in blank
hard

Fill both blanks to create a custom error with code and a nested details object.

GraphQL
throw new GraphQLError('Error', { extensions: { [1]: 'BAD_REQUEST', [2]: { field: 'email', issue: 'invalid format' } } });
Drag options to blanks, or click blank then click option'
Acode
Bmessage
Cdetails
Dinfo
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping 'code' and 'message' keys.
Using 'info' instead of 'details' for nested error data.
5fill in blank
hard

Fill all three blanks to throw a GraphQL error with uppercase code, numeric status, and a user-friendly message.

GraphQL
throw new GraphQLError('Access denied', { extensions: { [1]: 'FORBIDDEN', [2]: 403, [3]: 'You do not have permission to access this resource.' } });
Drag options to blanks, or click blank then click option'
Acode
Bstatus
Cmessage
Derror
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'error' instead of 'message' for the user message.
Confusing 'status' with 'code' for the numeric value.