In any assessment platform, reliability and robust error handling are crucial to ensuring a smooth user experience for students. When using Custom Questions within Learnosity, there are specific best practices to handle errors effectively, particularly when working with scorers and external resources. Below are guidelines and recommendations to ensure your Custom Questions operate reliably and errors are managed efficiently.
Handling Errors When Loading External Resources
When your Custom Question relies on external resources (e.g., scripts, libraries, or APIs), network errors can sometimes cause these resources to fail to load. To mitigate this:
- Implement Retry Logic: If an external resource fails to load, retry the loading process up to three times, introducing a small delay between each retry.
- Graceful Failure: If all retries fail, display an informative error message in the UI to notify the student. Alternatively, throw an error that stops the assessment to prevent incomplete or erroneous attempts.
Defensive Coding with Scorers
Scorers are critical components that process responses and generate scores. When handling scoring logic:
- Be Defensive: Anticipate potential errors and exceptions in your code. Use defensive programming techniques such as validating inputs and handling edge cases.
- Error Logging: If an error occurs, especially on the server side, log it for later analysis. Learnosity uses Graylog to track server-side errors, but only uncaught exceptions are logged. If you catch the error within your code, it will not be logged in Learnosity’s system.
Responsibility for Logging
- If your Custom Question code catches an error, you are responsible for logging it.
- Recommended Logging Options:
- Use a third-party logging service
- Log errors to your own database.
Storing error information in response values is not recommended because it makes error analysis difficult. Tracking errors through a dedicated logging service or database makes it easier to analyze issues by device, browser, frequency, and other factors.
Displaying Errors in the UI
When an error occurs, provide clear feedback to students to avoid confusion:
- Frontend Error Messages: Display an appropriate UI message informing students that something went wrong.
- Assessment Halt: If the error is critical, consider stopping the assessment to prevent invalid submissions.
Example message:
"An error occurred while loading this question. Please refresh the page or contact your instructor."
Recommended Error Handling Flow
To summarize, here’s the recommended error-handling flow for Custom Questions:
- For External Resources:
- Attempt to load the resource with up to 3 retries.
- Display an error message if loading fails.
- For Scorers:
- Write defensive code to minimize errors.
- If an error occurs:
- Log it using a third-party service or your own database.
- Avoid logging it in the response value.
- Display a user-friendly message to the student.
Conclusion
Following these best practices will ensure that errors in Custom Questions are managed efficiently, reducing user disruptions and improving the overall assessment experience.