auth-js
auth-js copied to clipboard
FetchError: Unexpected token < in JSON at position 0
Bug report
Describe the bug
Hi guys! I'm using Supabase in one of my projects and I face a really weird issue. First I thought it's related to the JS version of the superbase-js library (some people reported the same error). Updating the client fixed that, but then the issue reappeared again.
I see
error { message: 'FetchError: invalid json response body at https://tcmqmkigakxeiuratohw.supabase.co/rest/v1/mirroritems_test?select=*&order=timestamp.desc.nullslast&limit=19 reason: Unexpected token < in JSON at position 0', details: '', hint: '', code: '' }
To Reproduce
I use the alpha preview of functions. The last time Supabase was down it coincide with the function that was triggered. Not sure if it caused an issue or not. If I mock the data and trigger the function myself, it works correctly. I don't have a clue how to reproduce it exactly, it seems to me that it's not the issue with the client or framework I use. But just in case, I use next.js "11.1.2" with "@supabase/supabase-js": "^1.28.5",
Restarting the server seems to fix the issue.
Expected behavior
Stable runtime.
Screenshots
![issue](https://user-images.githubusercontent.com/50060130/145830719-8b279a53-9bdb-4b1e-b485-a145496fe2c7.png)
System information
- OS: macOS
- Version of supabase-js 1.28.5
- Version of Node.js: v14.15.1
very odd - it seems that it's trying to decode the response but the response is not being returned as JSON. Are you able to give us some steps to reproduce this @noskovvkirill ?
@kiwicopple Not really, not sure what is happening exactly. I will try to monitor it and see if I can reproduce it. It happened two times within the last couple of days. I thought it's related to https://github.com/supabase/supabase-js/pull/305, but the client update didn't fix that.
@kiwicopple It happens again 😅 This time database reload doesn't help. I've tried to fetch different tables, but the issue seems to appear independent of the content! API page is not displayed on Supabase own front-end.
![Снимок экрана 2021-12-15 в 14 19 58](https://user-images.githubusercontent.com/50060130/146193943-2958b78a-f493-469d-ba99-a6e1c2bf6e23.png)
The website is currently down. Only cached pages are working. Help 🙏
@noskovvkirill - can you please submit a support ticket here: https://app.supabase.io/support/new
Thanks!
Having a similar issue.
had the same issue until i turned off RLS
Turning off RLS had no effect - still running into the issue randomly.
Hi all 👋
In order to get a more helpful error response, we have recently updated our JS libraries (to get in the fixes for this issue in the supabase/postgrest-js
library via this PR). Would you mind taking the following steps to upgrade it:
- Run
npm run update
within your directory. -
@supabase/postgrest-js
should then now be in version 0.35.1 or above. To verify this, you can runnpm list @supabase/postgrest-js
.
This won't solve the issue at hand but at the very least we should now get a less vague, and hopefully more insightful response than Unexpected token < in JSON at position 0
, and should eventually direct all of us to the root cause/s.
I'll close this for now as this issue should be solved on the latest library version
Got the same issue yesterday around 11:20 IST
Got the same issue today
I got the same issue today
FYI, we're tracking this one in https://github.com/supabase/postgrest-js/issues/282
Just experienced the same issue and it caused my server to crash. I believe it happened as a result of calling:
const { user, error } = await supabase.auth.api.getUser(token)
// Error message:
// FetchError: invalid json response body at https://fmapsufvoocumtvhyody.supabase.co/auth/v1/user
// reason: Unexpected token < in JSON at position 0
// This line within node-fetch threw the error:
// return Body.Promise.reject(new FetchError(`invalid json response body at ${_this2.url} reason: ${err.message}`, 'invalid-json'));
While the root of this bug is being fixed, in the meantime is there some way to capture the error and reveal it in the returned .error prop of the supabase response object instead of allowing the supabase SDK method to throw?
I assume most codebases will not expect supabase methods to throw... this is what caused my server to crash. If the error was passed along via the error prop, my code would have handled it properly.
Right now, I'm forced to wrap all of my supabase SDK API methods in a try-catch which is redundant & messy.
I've repeatedly run into this problem while trying to do bulk operations on auth.api.getUser
/ auth.api.createUser
to synchronize a new Supabase project with a (for now) external source of truth on users. Even when rate-limiting my operations to a max of 20 in parallel, I have to put extensive retry logic on anything that touches auth.api
.
I seriously don't understand what it's doing, because at this point I could probably just start direct inserting into the users
table instead and have more success, and I've already started using a view on users
as a workaround instead of using getUser
.
@miketromba @icopp Though the error message is the same, the issue you mention comes from the Auth API(GoTrue) and that's not used by postgrest-js
.
Perhaps you could open an issue on https://github.com/supabase/gotrue-js/ for better visibility?
This seems to be a class of errors rather than a single isolated error some of which arise from the createUser/getUser endpoints. Moving to Auth repo to triage
@J0 In my understanding deep down it is all related to a single problem. Where database is not responding in timely manner, Thus causing the related API to timeout. As Supabase client library always expect API response to be a valid JSON it is thrwoing errors on not getting one. But these are all related to the API timeout.
There is something seriously wrong with the memory management/Reporting at supabase end. Anyone who is facing these issues just Increase the RAM and 90% of these issues will be gone, No matter how much RAM is free on your server.
ran into same issue today! :|
Hey everyone, just wanna check if this issue has been fixed? We noticed an issue with our internal api-gateway where there was an error parsing certain JWTs sent. We've since rectified the issue awhile back.
I don't think that this is an issue with the gotrue-js client library as I can't seem to reproduce it while running gotrue locally and directly connecting to it via my client app.
If anyone is still facing this issue, can you please reach out to us at support and we'll get to the bottom of it!
Hey everyone, just want to give some context on errors that say Unexpected token < in JSON at position 0
. This is a class of errors that occurs usually when the underlying server is down and the CDN is rendering a 5XX response page with HTML. The error comes because all HTML starts with <!DOCTYPE...
.
If you see this, it's probably not connected to the way you're using the API and means that something crashed, is not reachable or timed out.
What fixed it for me was using encodeURIComponent
for my storage bucket path that had spaces in it. I assume that if the path isn't encoded properly it hits a bad url and the server responds with a non-json 404 response, hence the < in jSON at position 0