Response Handler
In ReqEase, response handlers play a vital role in processing and rendering the responses received from HTTP requests. These handlers are designed to provide a smooth and user-friendly experience when dealing with various types of server responses. Let's dive into the world of response handlers.
Base Response Handler
The foundation of all response handlers in ReqEase is the ResponseHandler
class:
static label: string
: Each response handler has a label to identify its type.requester: Requester
: A reference to the Requester instance responsible for the HTTP request.response: Responses.Response | BaseCustomResponse
: The received response to be handled.retry: () => void
: A function to retry the request if needed.
Message Response Handler
One of the built-in response handlers is the MessageResponseHandler
, used for handling messages sent by the server. Here's an overview:
static label = "message"
: This label identifies the handler as a message response handler.response: Responses.Message.MessageResponse
: This response handler specializes in handling message responses.modalHandler
: A reference to the modal handler if the response type requires a modal.message
: An instance of a message renderer for rendering messages.
Custom Response Handlers
If your server sends responses in a format not recognized by the built-in handlers, you have the flexibility to create custom response types and their respective handlers. To achieve this:
Create a custom response that extends
BaseCustomResponse
:
Develop a custom response handler with a label matching your custom response.
Register your custom response handlers within the Requester configuration using the
responseHandlersToRegister
option.
By following these steps, you can tailor response handling in ReqEase to accommodate unique server responses, ensuring a seamless user experience in your web application. Customization allows you to adapt to the specific requirements of your project and extend ReqEase's capabilities as needed.
Last updated