seratch / notion-sdk-jvm

A Notion SDK for Any JVM Language
https://developers.notion.com/
MIT License
137 stars 25 forks source link

Exception while retrieving some blocks #85

Open ksharma96 opened 1 year ago

ksharma96 commented 1 year ago

Hey @seratch , GsonSerializer is failing with the following two calls to the API in the SDK : NotionClient.retrievePage NotionClient.retrieveBlockChildren

Any idea why this could be? Any workarounds, something I've configured wrong?

Attaching the logs below

====================================================================================


2023-02-09T12:49:13.911+05:30   com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $
2023-02-09T12:49:13.911+05:30   at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:395)
2023-02-09T12:49:13.911+05:30   at com.google.gson.Gson.fromJson(Gson.java:1214)
2023-02-09T12:49:13.911+05:30   at com.google.gson.Gson.fromJson(Gson.java:1124)
2023-02-09T12:49:13.911+05:30   at com.google.gson.Gson.fromJson(Gson.java:1034)
2023-02-09T12:49:13.911+05:30   at com.google.gson.Gson.fromJson(Gson.java:969)
2023-02-09T12:49:13.911+05:30   at notion.api.v1.json.GsonSerializer.toError(GsonSerializer.kt:67)
2023-02-09T12:49:13.911+05:30   at notion.api.v1.endpoint.BlocksSupport$DefaultImpls.retrieveBlockChildren(BlocksSupport.kt:126)
2023-02-09T12:49:13.911+05:30   at notion.api.v1.NotionClient.retrieveBlockChildren(NotionClient.kt:12)

====================================================================================

22023-02-09T13:17:27.838+05:30  com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $
2023-02-09T13:17:27.838+05:30   at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:395)
2023-02-09T13:17:27.838+05:30   at com.google.gson.Gson.fromJson(Gson.java:1214)
2023-02-09T13:17:27.838+05:30   at com.google.gson.Gson.fromJson(Gson.java:1124)
2023-02-09T13:17:27.838+05:30   at com.google.gson.Gson.fromJson(Gson.java:1034)
2023-02-09T13:17:27.838+05:30   at com.google.gson.Gson.fromJson(Gson.java:969)
2023-02-09T13:17:27.838+05:30   at notion.api.v1.json.GsonSerializer.toError(GsonSerializer.kt:67)
2023-02-09T13:17:27.838+05:30   at notion.api.v1.endpoint.PagesSupport$DefaultImpls.retrievePage(PagesSupport.kt:81)
2023-02-09T13:17:27.838+05:30   at notion.api.v1.NotionClient.retrievePage(NotionClient.kt:12)
2023-02-09T13:17:27.838+05:30   at notion.api.v1.endpoint.PagesSupport$DefaultImpls.retrievePage(PagesSupport.kt:68)
2023-02-09T13:17:27.838+05:30   at notion.api.v1.NotionClient.retrievePage(NotionClient.kt:12)
ksharma96 commented 1 year ago

The problem seems to be when the API doesn't get a 200 response in the BlocksSupport.kt file.

      `error = jsonSerializer.toError(httpResponse.body)`

while parsing the error response, it's getting a String instead of an Object: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path

ksharma96 commented 1 year ago

Just adding on to what might help: Encountered a response from Notion's API which had the body as shown below: body <html> 2023-01-31T19:15:44.238+05:30 <head><title>504 Gateway Time-out</title></head> 2023-01-31T19:15:44.238+05:30 <body> 2023-01-31T19:15:44.238+05:30 <center><h1>504 Gateway Time-out</h1></center> 2023-01-31T19:15:44.238+05:30 </body> 2023-01-31T19:15:44.238+05:30 </html>

Since the body was not a json, it was failing in the Parser. Can we please add a handling of such a scenarios @seratch ?

Again, thanks a lot for your SDK, much grateful.

seratch commented 1 year ago

@ksharma96 Thanks for reporting this issue. This should be improved in future versions.