Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HttpRequest doesn't provide a way to capture error deseriliser type #5

Open
rajkumarpalani opened this issue Feb 10, 2021 · 0 comments

Comments

@rajkumarpalani
Copy link

General information

  • SDK/Library version: All
  • Java Version: All

Issue description

HttpRequest allows to define a response payload deserialiser but doesn't have options to specify an error deserialiser. Any non 2xx status response triggers a HttpException and the error message is deserialised to String leaving clients to parse/deserialise back to an error entity

Problem:

       try { 
           HttpResponse<CreatePayoutResponse> response = client.execute(request);  
        } catch (HttpException e) {  
            String error = e.getMessage();  
           //Client to parse the error string to understand fields
        }  

Possible Solution:
Clients are expected to either parse the string to understand the fields or deserialise the entity themselves like

       try { 
           HttpResponse<CreatePayoutResponse> response = client.execute(request);  
        } catch (HttpException e) {  
            String error = e.getMessage();  
            Encoder encoder = new Encoder();  
            Error payoutError = encoder.deserializeResponse(new ByteArrayInputStream(error.getBytes(StandardCharsets.UTF_8)), Error.class, e.headers());  
            System.out.println(payoutError);  
        }  

Expectation:
It would improve the integration experience to allow the error type be available in the HttpException

       try { 
           HttpResponse<CreatePayoutResponse> response = client.execute(request);  
        } catch (HttpException e) {  
            Error payoutError = e.getError(); 
            System.out.println(payoutError.getName()); 
        }  
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant