-
-
Notifications
You must be signed in to change notification settings - Fork 997
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
Handle Non-JSON Error Responses from Providers #3389
base: main
Are you sure you want to change the base?
Conversation
Handle Non-JSON Error Responses from Providers Some providers, return error responses as strings instead of JSON objects. For example, getBlock.io returns "rate limit reached" as a plain string, causing a SyntaxError when attempting to parse it as JSON:
|
@yogaajs is attempting to deploy a commit to the Wevm Team on Vercel. A member of the Team first needs to authorize it. |
src/utils/rpc/webSocket.ts
Outdated
const _data = JSON.parse(data); | ||
onResponse(_data); | ||
} catch (error) { | ||
onResponse(data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably here should be onError(error)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not an error, if the provider returns a string instead of an object the message is still valid.
It's just that on the provider side it's "badly done" since it should return an object with the error, the code etc...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but according to onResponse
type https://github.com/wevm/viem/blob/main/src/utils/rpc/socket.ts#L22 it only accept RpcResponse
object and can't accept string as argument
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right on that point, I hadn't seen it that way, but a rate limit is sort of an error. In reality anything that is not an rpc response is an error.
Some providers, return error responses as strings instead of JSON objects. For example, getBlock.io returns "rate limit reached" as a plain string, causing a SyntaxError when attempting to parse it as JSON.