However, the default response generated by Imperva may not be appropriate for a couple of different reasons:
- By default, Imperva expects clients to be communicating using HTML and sends error messages formatted in HTML as well. If an API client is expecting JSON-formatted responses, then it will be incapable of parsing the error message sent by Imperva.
- Another reason why error responses may need rewriting is that an API’s schema may define a special error response format. If this is the case, it is unlikely that the default Imperva response matches this format. As a result, even if the response is JSON-formatted, it may not be possible for the client to interpret it properly.
In these two cases, the default error messages generated by Imperva will cause issues with an API client. This is why the ability to create error messages is useful for API developers.
Creating a Custom Error Response in Imperva
Custom error responses in Imperva take advantage of the ability to enforce API schema definitions. For more information about how to load and enforce an API schema in Imperva, check out this video.
Configuration Settings
By default, Imperva is going to assume that requests to a webpage are going to be performed using HTML. As a result, when an error occurs - such as violating the API schema - Imperva will send back an HTML-formatted error page.
While this is the default, it is not the only option. Imperva is capable of returning responses based upon the content type of a request; however, this requires changing a setting within the Imperva dashboard.
With a particular website’s page, select the Settings option on the menu on the left-side of the screen. Inside of this page, select General, then scroll to the bottom of the Page.