redux-toolkit: How can I get the url of the API in the error middleware?

I am using a pretty standard implementation of RTK query from the docs nothing too fancy. I have a situation where I would want to know the API URL that failed in the error middleware.

I checked in the docs and few other sites but could not find it. Here is my error middleware:

`export const errorMiddleware: Middleware = (store) => (next) => (action) => { /**Rejection from interal redux cache we want to ignore it since it is not a rejection:

*/ const conditionError = ‘ConditionError’; /**If we got actual rejection from the APIs than show a toast */ if ( isRejectedWithValue(action) || (action.type.endsWith(‘/rejected’) && action.error.name !== conditionError) ) { console.log(action.meta.url??? ); console.log(store); store.dispatch( showToast({ message: action.error.message, type: ‘error’ }) ); } return next(action); }; ; `

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 16

Most upvoted comments

assuming you’re using fetchBaseQuery, request and response objects are attached to action.meta.baseQueryMeta - this presumably will have the URL and status information you want.

proving this in typescript will probably be a little harder, without some type assertions.

I also want to get the status code as well.