How erick03/handle_retrofit_error works
Main Components
• Model Layer: Contains the TempError class (in the “model” directory), which represents the custom error object.
• Utility Layer: The “Utils” class (in the “utils” directory) that hosts the parseError method. This component acts as a converter between the raw error response from Retrofit and the custom TempError object.
• Web Service/Networking Layer: Under the “webservice” directory, you have:
– RestClient.java: A singleton class that initializes the Retrofit client (and its underlying OkHttpClient) and manages the addition of a RequestInterceptor.
– RequestInterceptor.java: A custom interceptor to manipulate or add header information before requests are sent.
– RestInterface.java: Likely defining the Retrofit API endpoints.
• External Libraries: Retrofit (and by proxy, OkHttp) plays a central role in the network communications and error handling.
• Design a “Web Service” module that includes:
• RestClient (singleton for building the Retrofit instance)
• RequestInterceptor (added to the OkHttpClient for header manipulation)
• RestInterface (defining service endpoints)
• A connection from the application’s networking layer (which uses Retrofit) to the RestClient.
• From the RestClient, show that it configures the OkHttp client with the RequestInterceptor.
• When a request is executed, illustrate the flow:
a. A service call is initiated via RestInterface.
b. The response is evaluated (if successful, it proceeds normally).
c. For error responses (status code > 400), the error body flows to the Utils class (specifically the parseError method).
d. The Utils class converts the raw error into a TempError instance.
Architectural Style and Patterns
• Client-Interceptor Pattern: Show that the RequestInterceptor is injected into the OkHttpClient to specifically handle header modifications.
• Dependency Flow: Clearly indicate how Retrofit (an external library) is incorporated by the RestClient and how its response is processed in the Utils module.
Detailing the Technical Stack
• Mention that the Retrofit library is used to construct the HTTP client.
• That OkHttp’s interceptor functionality is leveraged by the RequestInterceptor.
• That the Utils class’s parseError method uses Retrofit’s responseBodyConverter to convert error responses into the custom TempError, handling potential IOException.
• Below, have a “Webservice / Networking” section:
□ RestInterface (API endpoints)
□ Utils.parseError → resulting in a processed TempError (in the Model module).
Happy diagramming!