Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

Proper error handling using Redux Toolkit

$
0
0

Say for example when a login function calls an API and it returns an error because of something like invalid credentials. I have noticed that it still goes through the fulfilled case in the extra reducers part. Should I add an if statement to check if response code is 200 or is there a way for the thunk to go through the rejected case?

extraReducers: builder => {    builder.addCase(login.pending, (state, action) => {      state.fetchingError = null;      state.fetchingUser = true;    });    builder.addCase(login.fulfilled, (state, {payload}) => {      console.log(payload, 'hello?');      state.user = payload.data.user;    });    builder.addCase(login.rejected, (state, action) => {      state.fetchingUser = false;      state.fetchingError = action.error;    });  },

Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>