Read standard details from rejected thunk actions
Thunk failure handling
Redux Toolkit · Type Alias
SerializedError is Redux Toolkit’s plain, serializable representation of an error. It optionally carries the error name, message, stack, and code.
SerializedError is the plain error shape Redux Toolkit uses after serializing an error. Its four optional string properties preserve common diagnostic details without requiring an Error instance.
export interface SerializedError {
name?: string
message?: string
stack?: string
code?: string
}import type { SerializedError } from '@reduxjs/toolkit'
export function formatError(error: SerializedError): string {
return error.message ?? error.name ?? 'Unknown error'
}
Accepts the documented optional fields and safely chooses a display string.
Thunk failure handling
RTK Query error handling
Error display
SerializedError is an interface with optional string properties named name, message, stack, and code. It describes a serializable error value rather than an Error instance.
Follow-up: Why are its properties optional? Serialization may receive values that do not provide every conventional Error field, so consumers must handle missing fields.
createAsyncThunk uses an automatically serialized error in the rejected action when the promise fails without rejectWithValue. The resulting value is available as action.error.
Follow-up: How can a thunk provide a custom structured failure? Catch the failure and return thunkAPI.rejectWithValue(value), which places that value in action.payload.
The documented declaration is export interface SerializedError { name?: string; message?: string; stack?: string; code?: string }. Every field is optional and has type string.
Follow-up: What should TypeScript code do before accessing a union containing this type? Narrow the union to SerializedError or another known error shape first.
miniSerializeErrorcreateAsyncThunkFetchBaseQueryErrorrejectWithValue