A. The server could not process the request because the email and password fields are invalid.
B. The server processed the request successfully with no errors.
C. The server is down and cannot handle requests.
D. The client is not authorized to access this resource.
Solution
Step 1: Analyze the status code
Status 422 means the server understood the request but found invalid data.
Step 2: Interpret the errors object
The errors show specific problems: invalid email format and password too short.
Final Answer:
The server could not process the request because the email and password fields are invalid. -> Option A
Quick Check:
422 + errors = invalid input fields [OK]
Hint: 422 with errors means input fields have problems [OK]
Common Mistakes:
Thinking 422 means server failure
Ignoring the errors object details
Assuming success when status is 422
4. You wrote this code snippet in a REST API controller:
if (!user.email.includes('@')) {
res.status(422).json({ error: 'Invalid email' });
}
// further processing
But clients report they still get 200 OK even with invalid emails. What is the likely bug?
medium
A. The client is ignoring the 422 status code.
B. The status code 422 is not supported by REST APIs.
C. The function does not return after sending the 422 response, so processing continues.
D. The email validation logic is correct, so the bug is elsewhere.
Solution
Step 1: Check response flow
After sending a response, the function must stop further processing to avoid sending another response.
Step 2: Identify missing return
If return is missing before res.status(422)..., the code continues and may send 200 OK later.
Final Answer:
The function does not return after sending the 422 response, so processing continues. -> Option C
Quick Check:
Return after res.status(422) to stop processing [OK]
Hint: Always return after sending 422 response to stop code [OK]
Common Mistakes:
Not returning after sending response
Misunderstanding 422 support in REST
Blaming client instead of server code
5. You are designing a REST API endpoint for user registration. Which approach best uses the 422 status code to improve client communication when input data is invalid?
hard
A. Return 422 with a JSON object listing each invalid field and a clear error message.
B. Return 422 with a generic message: 'Invalid data'.
C. Return 400 Bad Request without details about the errors.
D. Return 200 OK and ignore invalid fields silently.
Solution
Step 1: Understand purpose of 422
422 is used to tell clients exactly what data is invalid to help fix input.
Step 2: Choose detailed error reporting
Providing a JSON object with each invalid field and message improves client experience.
Final Answer:
Return 422 with a JSON object listing each invalid field and a clear error message. -> Option A