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

SDK should not assume response will be application/json when it does not require it in the Accept header #7

Open
efibe opened this issue Oct 15, 2021 · 0 comments

Comments

@efibe
Copy link

efibe commented Oct 15, 2021

When I send a request that results in a response with status other than HTTP_OK (200), the API server is currently replying in a format that is not JSON (probably HTML, due to some application firewall at Gerencianet's cloud).

When the response arrives, an exception is being thrown at line 59 of at br/com/gerencianet/gnsdk/Request.java with the following stacktrace:

org.json.JSONException: A JSONObject text must begin with '{' at 1 [character 2 line 1] at org.json.JSONTokener.syntaxError(JSONTokener.java:451) at org.json.JSONObject.<init>(JSONObject.java:195) **at br.com.gerencianet.gnsdk.Request.send(Request.java:59)** at br.com.gerencianet.gnsdk.APIRequest.send(APIRequest.java:59) at br.com.gerencianet.gnsdk.Endpoints.kernelCall(Endpoints.java:80) at br.com.gerencianet.gnsdk.Endpoints.call(Endpoints.java:61)

The code is assuming the response will always be in JSON format, but it does not specify that requirement in the Accept header of the request.

To fix the issue, this class must include a header "Accept: application/json" (provided that the server honors it).

@efibe efibe changed the title SDK should not assume response will be application/json when it does not require it Accept header SDK should not assume response will be application/json when it does not require it in the Accept header Oct 15, 2021
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