Skip to content

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

@efibe

Description

@efibe

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions