You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I recently had this issue as well. We rely on the meta property in some of our listeners, but this broke when adding the retry functionality and bailing out early. The issue specifically is that in the fail method, instead of passing e into HandledError, it's passed to an object {error: e} which I believe is incorrect. Until this is fixed in the library itself, this was my workaround:
classHandledError{constructor(publicreadonlyvalue: any,publicreadonlymeta: any=undefined,){}}// Replicates the behavior of `retry` from `redux-toolkit/query/react` but passes the full result instead of just the error// @see https://github.com/reduxjs/redux-toolkit/issues/3789functionfail(e: any): never{throwObject.assign(newHandledError(e),{throwImmediately: true,})}// Allows us to bail out of retries by executing {fail} with the entire resultfunctionretryableBaseQuery<Textendsany[],R>(baseQueryFn: (...args: T)=>R|PromiseLike<R>){returnasync(...args: T): Promise<R>=>{try{returnawaitbaseQueryFn(...args)}catch(error){// Used to handle bailing out of retriesif(errorinstanceofHandledError){returnerror.value}throwerror}}}
Now if I use my fail method, I get the proper meta and payload for RTK queries
Currently, if you use
retry
withfetchBaseQuery()
, and you bail out early (eg, because of a 4xx status), then the result is missingmeta
data.The code for
fail
is:So
retry.fail()
is only returning / throwing the error, and not returning the meta, althoughHandledError
is capable of handling meta:The text was updated successfully, but these errors were encountered: