Errors happen. Users should know when errors are happening, but we want to provide them with useful guidance and messaging when errors to occur. The API generally returns 4 types of errors:
400 Bad Request - Something was wrong with the incoming request. In many cases, we want to provide guidance to the user as to how to fix their request for subsequent requests.
401 Unauthorized - You aren't logged in or do not have permission to view the resource.
404 Not Found - The API endpoint was not found.
500 Internal Server Error - The error happened on the server. We don't want to provide any details about the error to the end user, but want to notify the developer or system administrator about error details so that it can be fixed.
Upon navigating to the Error Message admin page, you'll see this:
Let's observe the following:
You can filter by name.
Add Error Message button - will bring up the Add form to add a new 400 error message handler.
Test 500 Error button - will simulate an internal server error.
Test 400 Bad Request button - will simulate a 400 Bad request that will invoke the sample handler "Test Bad Request" that is set up already in the screenshot.
Test 404 Not Found button - will simulate a 404 not found response from the API.
Search Results - The list of error messages filtered by the search form at the top of the page.
Automated 500 Internal Server Error Handling
When a 500 Internal Server error occurs, an administrator will be emailed details about the issue. The recipients for automatic error messages is configured in the API's appsettings.json file.
Here is a sample of what an automated error message email looks like:
However, for security and usability reasons, we don't want to show the user any details about an error, but simply that someone has been made aware of the issue and what to do if they need further assistance. Clicking the "Test 500 Error" button will invoke a server error and show the following message:
Guided 400 Bad Request Error Handling
The Custom Error Messages that are configurable through this admin area are intended to offer guidance and further instructions to users who submit a bad request. Below is an example of a custom dialog that handles the sample error message that is setup by default by clicking the "Test 400 Bad Request" button:
Configuring Custom Error Messages for Bad Request Error Handling
When clicking on the Edit option next to the Test Bad Request that is there by default, we see the following data entry form:
Here's a description of the form fields:
Name - The friendly name of the request and text that will be displayed in the title of the modal.
Error Message Contains Text - This text is what is searched for in an error message that would determine the error message to display.
Explanation - This is the text that appears in the text area of the modal and provides explanation for the error and/or any instructions on how to proceed.
Action URL or Route - A route in your local angular app or external URL to visit in response to the error.
Action Text - The text that will be displayed as the link text to the specified URL or Route above.
Show Error Message - If this is enabled, the actual error message returned from the server will appear in the modal.
Suppress Error Message - If this option is enabled, no error handling UI will appear for this error.
404 Not Found Error Handling
Currently, we don't do anything about reporting 404 errors, but we do let the user know that something went wrong: