prismicio-community / java-kit

Community maintained development kit for Prismic and the Java language
https://prismic.io
15 stars 38 forks source link

NullpointerException when REST call returns error #51

Open sgruenheit opened 7 years ago

sgruenheit commented 7 years ago

Hi Team!

We experience NullPointerExceptions int the api when some queries fail:

java.lang.NullPointerException at io.prismic.core.HttpClient.fetch(HttpClient.java:59) at io.prismic.Form$SearchForm.submit(Form.java:412)

The response that cannot be processed looks like this:

{"message":"Release not provided"}

srenault commented 7 years ago

Very weird!

The Release not provided message is return is you don't pass ref parameter.

sgruenheit commented 7 years ago

I think this is related to the new multi-language feature. I guess this happens when we query a document which doesn't exist in the language given.

srenault commented 7 years ago

Ok, I'm going to investigate! Thanks for your report!

bgooren commented 5 years ago

I'm getting an NPE in the HttpClient as well:

Caused by: java.lang.NullPointerException
    at io.prismic.core.HttpClient.fetch(HttpClient.java:62)
    at io.prismic.Form$SearchForm.submit(Form.java:411)

This appears to be because the HttpClient expects an error response to have an "error" key (see below).

JsonNode errorJson = new ObjectMapper().readTree(httpConnection.getErrorStream());
        if (errorJson != null) {
          errorText = errorJson.get("error").asText();
        }

When inspecting the actual response, it does not have an "error" key:

{"message":"[function at(..)] unexpected field 'my.city' on line:1 col:59 in query '[[:d = at(document.type, \"flower_delivery_page\")][:d = at(my.city, \"Antwerpen\")]]'\n[[:d = at(document.type, \"flower_delivery_page\")][:d = at(my.city, \"Antwerpen\")]]\n                                                          ^\n","type":"parsing-error","line":1,"column":59,"id":0,"location":"query"}

So the client is expecting an error response to have the "error" key (thus not checking for null), which leads to a NPE. Did the api change to put the error in the "message" key?

bgooren commented 5 years ago

Hi Team! Can you please respond to this issue? It's rather ugly to have to catch NullPointerException when using your (java) api. Thanks!

damienbeaufils commented 5 years ago

Hello @bgooren. This PR https://github.com/prismicio/java-kit/pull/69 should fix this issue. Maybe add a thumbs-up or a comment on it? :)

bgooren commented 5 years ago

Hello @bgooren. This PR #69 should fix this issue. Maybe add a thumbs-up or a comment on it? :)

Thanks! I gave it a thumbs up. It's a shame the java kit is updated so little...