Error displays as an empty object #1552
Send to my agentWhen my query function throws an error, the devtools displays it as an empty object.
I would expect it to display the message and maybe stack string properties that the object contains.
If I throw a custom error with additional properties, such as status, it shows up just fine in the devtools. So it seems to only be the default error properties that are not being shown.

tannerlinsley closed this
@tannerlinsley the feature is currently disabled because of some bugs - see: https://twitter.com/adamwathan/status/1347194195442851846
@tannerlinsley This probably should be open again. The string/object or whatever that is inside of the exception that is being thrown on the service called on the query is not appearing on the error object returned by the query
@tannerlinsley I had to throw this on the exception to make it work:
throw { asd: `${error}\n${result.originalError}` };instead of
throw new Error('content');If I throw the error, I am not able to access to the content
Can confirm, just run into this using axios interceptors:
Interceptor:
const testInterceptor = (error) => { throw new Error("Oh snap!") }Axios:
instance .request(requestParams) .then((response) => response.data) .catch((error) => Promise.reject(error)) instance.interceptors.response.use((response) => response, (error) => testInterceptor(error))isErroris updated, buterroris always an empty object. If I throw an object like @felire pointed out,erroris updated:const testInterceptor = (error) => { throw { error: "Oh snap!", code: error?.code } }@tannerlinsley shouldn't this be reopened? I'm on
v3.39, and I still get{}aserrorfromuseQuerywhen an instance ofErroris thrown inside a fetch function. As @felire has said, if you throw some custom object like{error: "some error"}, it's displayed correctly.yeah let's reopen this and fix it for v4. We initially only used
JSON.stringifyto display the values, but lots of things (Errorincluded) is not json serializable. That's why an object works, but an Error instance does not. Now, we have a custom function that serializesBigIntdifferently already:My idea would be to just use superjson here to cover all cases.
TkDodo reopened this
TkDodo added labelspackage: react-query-devtools
TkDodo added labelsenhancement
TkDodo added labelshelp wanted
TkDodo added labelsgood first issue
Hi @TkDodo! Could you please elaborate more on how exactly to use
superjson? ReplacingJSON.stringifywithSuperJSON.stringifyoutputs:export const displayValue = (value: unknown) => SuperJSON.stringify(value) displayValue(new Error('my message')) // {"json":{"name":"Error","message":"my message"},"meta":{"values":["Error"]}} displayValue(1n) // {"json":"1","meta":{"values":["bigint"]}}Replacing JSON.stringify with SuperJSON.stringify outputs:
I think we can do:
const { json, meta } = superjson.serialize(value)and then just ignore the
meta?TkDodo closed this
Sign in to join this conversation.
While this is important, I think it's merely a UX upgrade to the devtools rather than an issue. Closing for now (I would love to convert it to an "Idea" discussion, but for whatever reason, Github doesn't allow it for this issue, maybe because it's transfered?)