Handling Empty Results
When building complex queries with multiple filters, it is entirely possible to request a combination that does not exist in our database. For example, if you request JAMB Computer Studies questions from the year 2002, you will likely get no results because Computer Studies was introduced much later.
The 404 Status Code
2.16.1Instead of returning an empty array, SdashAPI strictly adheres to RESTful conventions. If no questions match your specific filters, the server will respond with an HTTP 404 Not Found status code and a JSON object containing an error message.
{
"status": 404,
"message": "No questions matched your filters, or unknown endpoint."
}Checking the Response Status
2.16.2In your frontend code, you must never blindly attempt to access data.question without first verifying the status. Attempting to iterate over a non-existent data array will crash your application.
const response = await fetch(url);
const json = await response.json();
if (json.status === 200) {
// Safe to render questions
renderQuiz(json.data);
} else if (json.status === 404) {
// Handle empty result gracefully
showEmptyStateUI("No questions found for this specific year. Try another year.");
} else {
// Handle server errors
showErrorUI("An unexpected error occurred.");
}Designing Empty States
2.16.3Good user experience dictates that you should anticipate these scenarios. Instead of showing a generic error alert, design a friendly "Empty State" component in your app. Offer the user a button to reset their filters, or suggest a different exam year where data is known to be abundant.