feat(curriculum): add express error handling quiz (#67357)

Signed-off-by: Kolade Chris <65571316+Ksound22@users.noreply.github.com>
This commit is contained in:
Kolade Chris
2026-05-23 13:22:54 +01:00
committed by GitHub
parent 0fcbf74446
commit f9f699e52b
4 changed files with 477 additions and 1 deletions
+6
View File
@@ -7252,6 +7252,12 @@
"In these lessons, you'll learn about error handling and health checks in Express." "In these lessons, you'll learn about error handling and health checks in Express."
] ]
}, },
"quiz-error-handling-in-express": {
"title": "Error Handling in Express Quiz",
"intro": [
"Test your knowledge of HTTP status codes, error handling, debugging, logging, health checks, and graceful shutdowns."
]
},
"exam-back-end-development-and-apis-certification": { "exam-back-end-development-and-apis-certification": {
"title": "Back-End Development and APIs Certification Exam", "title": "Back-End Development and APIs Certification Exam",
"intro": [ "intro": [
@@ -0,0 +1,454 @@
---
id: 6a04bbc9815e737ed711622e
title: Error Handling in Express Quiz
challengeType: 8
dashedName: quiz-error-handling-in-express
---
# --description--
To pass the quiz, you must correctly answer at least 18 of the 20 questions below.
# --quizzes--
## --quiz--
### --question--
#### --text--
What does the HTTP status code 201 mean?
#### --distractors--
The request succeeded with no response body.
---
The client is not authorized to access the resource.
---
The requested resource does not exist.
#### --answer--
A new resource was successfully created.
### --question--
#### --text--
Which status code indicates that the request succeeded but there is no response body?
#### --distractors--
`200`
---
`201`
---
`301`
#### --answer--
`204`
### --question--
#### --text--
What does the `304 Not Modified` status code tell the client?
#### --distractors--
The resource has moved to a new permanent URL.
---
The server is temporarily unavailable for maintenance.
---
Authentication is required to access the resource.
#### --answer--
Nothing has changed, so the client can use its cached version.
### --question--
#### --text--
What is the difference between status codes `401` and `403`?
#### --distractors--
`401` means the resource is not found while `403` means the server is down.
---
`401` means the request was malformed while `403` means the resource moved.
---
`401` means the server crashed while `403` means the request timed out.
#### --answer--
`401` means authentication is required while `403` means authenticated but does not have permission.
### --question--
#### --text--
Which status code means the server is temporarily overloaded or down for maintenance?
#### --distractors--
`500`
---
`502`
---
`301`
#### --answer--
`503`
### --question--
#### --text--
What does `res.status(200).json({ message: "Success" })` do in Express?
#### --distractors--
Sends a `200` response with a plain text message.
---
Sends a `200` response with no body.
---
Redirects the client to the success page.
#### --answer--
Sends a `200` response with a JSON body.
### --question--
#### --text--
What makes Express recognize a middleware function as an error handler?
#### --distractors--
It is placed at the top of the middleware stack.
---
It uses `res.error()` instead of `res.send()`.
---
It is defined inside a route handler.
#### --answer--
It has the parameters `err`, `req`, `res`, and `next`.
### --question--
#### --text--
Where should error-handling middleware be placed in an Express app?
#### --distractors--
Before all route definitions.
---
At the very top of the file, before any imports.
---
Inside the first route handler that might throw an error.
#### --answer--
At the end of the middleware stack, after all routes.
### --question--
#### --text--
In Express 4, what must you do to handle async errors in a route handler?
#### --distractors--
Throw the error directly from the route handler and let Node.js handle it at the process level.
---
Return the error object as a JSON response body with a 500 status code.
---
Use `process.on('uncaughtException')` to catch all unhandled async errors globally.
#### --answer--
Wrap async logic in `try/catch` and call `next(err)` to forward the error to the error handler.
### --question--
#### --text--
What is the purpose of an `asyncHandler` wrapper function in Express 4?
#### --distractors--
It converts synchronous route handlers into asynchronous ones automatically.
---
It automatically restarts the server and clears state when an error occurs.
---
It replaces the error-handling middleware placed at the end of the middleware stack.
#### --answer--
It avoids repeating `try/catch` in every route by forwarding rejected promises to `next`.
### --question--
#### --text--
How does Express 5 handle async errors differently from Express 4?
#### --distractors--
Express 5 requires adding a global `process.on('unhandledRejection')` listener to catch async errors.
---
Express 5 silently ignores async errors and only logs them to the console without stopping the app.
---
Express 5 requires every async route to define its own dedicated error-handling middleware function.
#### --answer--
Express 5 automatically forwards async errors and rejected promises to the error handler without needing `next(err)`.
### --question--
#### --text--
Where should a `404` catch-all middleware be placed in an Express app?
#### --distractors--
Before all other routes, at the top of the file.
---
Inside the error-handling middleware, as a fallback check.
---
At the very end, after the error-handling middleware.
#### --answer--
After all routes but before the error-handling middleware.
### --question--
#### --text--
Which of the following is a best practice for error handling in production Express apps?
#### --distractors--
Always send the full stack trace to the client for easier debugging.
---
Place error-handling middleware before your routes for faster processing.
---
Handle all errors, including 404s, inside a single middleware function.
#### --answer--
Log error details internally and return a user-friendly message instead of sending stack traces to users.
### --question--
#### --text--
How do you enable all of Express built-in debug messages when starting your app?
#### --distractors--
Pass `{ debug: true }` to the `express()` constructor.
---
Call `app.enable('debug')` before defining routes.
---
Add `require('express-debug')` at the top of your entry file.
#### --answer--
Set the `DEBUG` environment variable to `express:*` when running the app.
### --question--
#### --text--
What does `DEBUG=express:router node index.js` do?
#### --distractors--
Enables all Express debug output, including middleware, routing, and application-level events.
---
Disables all debug output entirely and runs the app in silent production mode.
---
Logs only incoming HTTP request details like method and URL to the terminal.
#### --answer--
Shows only router-related debug output, filtering out other Express namespaces.
### --question--
#### --text--
What is `morgan` used for in an Express application?
#### --distractors--
Automatically catching and forwarding async errors in Express route handlers to `next`.
---
Serving static files from a specified directory without defining individual routes.
---
Connecting Express to a relational database and logging all executed queries.
#### --answer--
Logging HTTP requests with details like method, URL, status code, and response time.
### --question--
#### --text--
What is the purpose of a health check route in an Express app?
#### --distractors--
To automatically restart the server and reroute traffic when incoming request volume is too high.
---
To record and forward all incoming HTTP requests to an external monitoring or analytics service.
---
To inspect and block requests from IP addresses that are not on an approved allow-list.
#### --answer--
To report whether the app is running correctly so load balancers and orchestrators can decide if the service is healthy.
### --question--
#### --text--
What does the `SIGTERM` signal tell a Node.js process to do?
#### --distractors--
Restart immediately, clear all in-memory state, and re-initialize all active connections.
---
Dump a full memory snapshot to disk for later analysis and debugging purposes.
---
Force-kill all active database connections and close all open file descriptors right away.
#### --answer--
Begin shutting down, giving the app a chance to finish existing work before exiting.
### --question--
#### --text--
What does calling `server.close()` do during a graceful shutdown?
#### --distractors--
Immediately terminates all active connections and exits the process.
---
Sends a 500 response to any clients currently connected.
---
Deletes all in-memory session data and restarts the server.
#### --answer--
Stops accepting new connections while allowing existing ones to finish.
### --question--
#### --text--
Why would you return a 503 status from your health check route during a graceful shutdown?
#### --distractors--
To log the shutdown event and timestamp to an external monitoring dashboard for audit purposes.
---
To force the orchestrator to immediately spin up a new replacement instance before shutdown completes.
---
To notify all currently connected clients that their active sessions have been saved successfully.
#### --answer--
To signal to the load balancer that the app is unavailable so it stops routing new traffic to it.
@@ -0,0 +1,13 @@
{
"isUpcomingChange": true,
"dashedName": "quiz-error-handling-in-express",
"blockLabel": "quiz",
"blockLayout": "link",
"helpCategory": "Backend Development",
"challengeOrder": [
{
"id": "6a04bbc9815e737ed711622e",
"title": "Error Handling in Express Quiz"
}
]
}
@@ -62,7 +62,10 @@
{ {
"dashedName": "error-handling-in-express", "dashedName": "error-handling-in-express",
"comingSoon": true, "comingSoon": true,
"blocks": ["lecture-understanding-error-handling-and-health-checks"] "blocks": [
"lecture-understanding-error-handling-and-health-checks",
"quiz-error-handling-in-express"
]
}, },
{ "dashedName": "websockets", "comingSoon": true, "blocks": [] }, { "dashedName": "websockets", "comingSoon": true, "blocks": [] },
{ "dashedName": "node-and-sql", "comingSoon": true, "blocks": [] }, { "dashedName": "node-and-sql", "comingSoon": true, "blocks": [] },