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

NullpointerException when REST call returns error #51

Open
sgruenheit opened this issue Aug 2, 2017 · 7 comments
Open

NullpointerException when REST call returns error #51

sgruenheit opened this issue Aug 2, 2017 · 7 comments

Comments

@sgruenheit
Copy link

sgruenheit commented Aug 2, 2017

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
Copy link
Contributor

srenault commented Aug 7, 2017

Very weird!

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

@sgruenheit
Copy link
Author

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
Copy link
Contributor

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

@bgooren
Copy link

bgooren commented Dec 14, 2018

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
Copy link

bgooren commented Jul 10, 2019

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
Copy link
Contributor

damienbeaufils commented Jul 10, 2019

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

@bgooren
Copy link

bgooren commented Jul 16, 2019

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

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

4 participants