Skip to content

How do I do reload on 401 and 403 responses from API? #4779

Closed Answered by EskiMojo14
steinarb asked this question in Q&A
Discussion options

You must be logged in to vote

Reducers should be pure and have no side effects - the right place for this would be in a middleware or a listener

import { isAnyOf } from "@reduxjs/toolkit"

const isRejectedRequest = isAnyOf(
  api.endpoints.getButikker.matchRejected,
  api.endpoints.getHandlinger.matchRejected,
  api.endpoints.getOversikt.matchRejected,
  api.endpoints.postEndrebutikk.matchRejected,
  api.endpoints.postNybutikk.matchRejected,
  api.endpoints.postNyhandling.matchRejected,
)

startListening({
  matcher: isRejectedRequest,
  effect: ({ payload }) => {
    const { originalStatus } = payload;
    const statusCode = parseInt(originalStatus);
    if (statusCode === 401 || statusCode === 403) {
        location.

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@steinarb
Comment options

@steinarb
Comment options

Answer selected by steinarb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants