0
0
NestJSframework~10 mins

Why structured errors improve API quality in NestJS - Test Your Understanding

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

Complete the code to throw a structured error with a message.

NestJS
throw new HttpException({ message: [1] }, HttpStatus.BAD_REQUEST);
Drag options to blanks, or click blank then click option'
A"Invalid input"
BInvalid input
C400
DHttpStatus.BAD_REQUEST
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the message string
Using a number instead of a string for the message
2fill in blank
medium

Complete the code to create a structured error with a custom error code.

NestJS
throw new HttpException({ message: 'Not found', code: [1] }, HttpStatus.NOT_FOUND);
Drag options to blanks, or click blank then click option'
A"404_NOT_FOUND"
B404_NOT_FOUND
CHttpStatus.NOT_FOUND
D"NOT_FOUND"
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name instead of a string
Omitting quotes around the code
3fill in blank
hard

Fix the error in the code to properly return a structured error response.

NestJS
return response.status(HttpStatus.BAD_REQUEST).json({ error: [1] });
Drag options to blanks, or click blank then click option'
A"Bad Request"
BHttpStatus.BAD_REQUEST
C{ message: 'Bad Request' }
DBad Request
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a plain string instead of an object
Using a variable without quotes
4fill in blank
hard

Fill both blanks to create a structured error with message and details.

NestJS
throw new HttpException({ message: [1], details: [2] }, HttpStatus.CONFLICT);
Drag options to blanks, or click blank then click option'
A"Conflict occurred"
B"Resource already exists"
C{ resource: 'User' }
D[ 'Duplicate entry' ]
Attempts:
3 left
💡 Hint
Common Mistakes
Using array instead of object for details
Omitting quotes around message
5fill in blank
hard

Fill all three blanks to create a structured error with message, code, and timestamp.

NestJS
throw new HttpException({ message: [1], code: [2], timestamp: [3] }, HttpStatus.INTERNAL_SERVER_ERROR);
Drag options to blanks, or click blank then click option'
A"Server error"
B"500_INTERNAL_ERROR"
Cnew Date().toISOString()
DDate.now()
Attempts:
3 left
💡 Hint
Common Mistakes
Using Date.now() which returns a number instead of string
Omitting quotes around strings