IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path
FHellmann opened this issue · 12 comments
java.lang.RuntimeException: retrofit.converter.ConversionException: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $
at edu.hm.cs.fs.app.database.error.HttpError.<init>(HttpError.java:30)
at edu.hm.cs.fs.app.database.error.ErrorFactory.http(ErrorFactory.java:22)
at edu.hm.cs.fs.app.database.model.LostFoundModel$1.failure(LostFoundModel.java:36)
at retrofit.CallbackRunnable$2.run(CallbackRunnable.java:53)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5294)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
Caused by: retrofit.converter.ConversionException: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $
at retrofit.converter.GsonConverter.fromBody(GsonConverter.java:67)
at retrofit.RetrofitError.getBodyAs(RetrofitError.java:137)
... 12 more
Caused by: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:200)
at com.google.gson.Gson.fromJson(Gson.java:810)
at com.google.gson.Gson.fromJson(Gson.java:775)
at retrofit.converter.GsonConverter.fromBody(GsonConverter.java:63)
... 13 more
Caused by: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $
at com.google.gson.stream.JsonReader.beginObject(JsonReader.java:387)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:189)
... 16 more
@jqbbq have you changed something in the rest interface, that this exception can be thrown? The exception occured the first time today.
I didn't change anything, but we had an server downtime today, so the REST was down and upon an request an 504 Bad Gateway was return. Could this be the reason?
I don't know. I wasn't able to reproduce this error since it came up.
A 504 Bad Gateway error would only be displayed and wouldn't crash the app.
It was a normal 504 and not an 504 packaged as an JSON
This error (504 Bad Gateway) already came up a few weeks ago. So I can say, that this is not the reason where this issue came from.
502 (bad gateway) and 504 (gateway timeout) are typical proxy problems. So your issue doesn't sound like a problem on your part.
This exception is the result of a failing convertion from json to object. So this is part of the rest service ;)
Using the 502/504 status code is the wrong way to handle parse errors. I would recommend to use 500 (Internal Server Error) or an appropriate 4xx status code if the REST client sends an illegal json request.
In case of an Error the REST-Service returns with the StatusCode 400 Bad Request, but still returns an valid JSON with additional information. I still believe the Exception was the result of the Server downtime, where the requests didn't reached the REST-Service, so the App didn't receive a valid JSON Response but an HTML Response somewhere.
This could be a possible solution. I will keep the issue open but mark it as waiting, while no new exceptions of this type are thrown. If this exception does not occure anymore, I will close the issue.
Doesn't occure since a month now... So this could be related to the downtime of the rest service.
This bug happend again on the 10. Nov. at 09:25 o'clock am. @jqbbq does the server was not reachable at this time?