Unverified Commit 958e34e0 authored by Jimmy Lai's avatar Jimmy Lai Committed by GitHub

actions: forward fetch rejections to the action handler (#49577)

Pretty edge case-y but this PR fixes the case where a fetch error happens for an action and we want to handle at the action handler level.



link NEXT-1123
parent a7fd95e3
...@@ -107,9 +107,10 @@ export function serverActionReducer( ...@@ -107,9 +107,10 @@ export function serverActionReducer(
fetchServerAction(state, action) fetchServerAction(state, action)
) )
} }
try {
// suspends until the server action is resolved. // suspends until the server action is resolved.
const { actionResult, actionFlightData, redirectLocation } = readRecordValue( const { actionResult, actionFlightData, redirectLocation } =
readRecordValue(
action.mutable.inFlightServerAction! action.mutable.inFlightServerAction!
) as Awaited<FetchServerActionResult> ) as Awaited<FetchServerActionResult>
...@@ -156,6 +157,13 @@ export function serverActionReducer( ...@@ -156,6 +157,13 @@ export function serverActionReducer(
action.resolve(actionResult) action.resolve(actionResult)
} }
} catch (e: any) {
if (e.status === 'rejected') {
action.reject(e.value)
} else {
throw e
}
}
action.mutable.serverActionApplied = true action.mutable.serverActionApplied = true
return state return state
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment