Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

76
Views
Manejo adecuado de errores usando Redux Toolkit

Digamos, por ejemplo, cuando una función de inicio de sesión llama a una API y devuelve un error debido a algo como credenciales no válidas. He notado que aun pasa por el caso cumplido en la parte de extra reductores. ¿Debo agregar una declaración if para verificar si el código de respuesta es 200 o hay alguna forma de que el thunk pase por el caso rechazado?

 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; }); },
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede usar el rechazo con createAsyncThunk rejectWithValue personalizar la acción de rechazo.

También toma un argumento que será "action.payload" en la acción de rechazo.

En createAsyncThunk :

 const updateUser = createAsyncThunk( 'users/update', async (userData, { rejectWithValue }) => { const { id, ...fields } = userData try { const response = await userAPI.updateById(id, fields) return response.data.user } catch (err) { // Use `err.response.data` as `action.payload` for a `rejected` action, // by explicitly returning it using the `rejectWithValue()` utility return rejectWithValue(err.response.data) } } )

https://redux-toolkit.js.org/api/createAsyncThunk#handling-thunk-errors

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!