mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
fix(actions): save error stack trace in memory (#11689)
This commit is contained in:
parent
315ec07e1b
commit
c7bda4cd67
2 changed files with 31 additions and 3 deletions
5
.changeset/silver-horses-beam.md
Normal file
5
.changeset/silver-horses-beam.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Fixes an issue in the Astro actions, where the size of the generated cookie was exceeding the size permitted by the `Set-Cookie` header.
|
|
@ -213,14 +213,16 @@ export type SerializedActionResult =
|
|||
|
||||
export function serializeActionResult(res: SafeResult<any, any>): SerializedActionResult {
|
||||
if (res.error) {
|
||||
if (import.meta.env?.DEV) {
|
||||
actionResultErrorStack.set(res.error.stack)
|
||||
}
|
||||
return {
|
||||
type: 'error',
|
||||
status: res.error.status,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
...res.error,
|
||||
message: res.error.message,
|
||||
stack: import.meta.env.PROD ? undefined : res.error.stack,
|
||||
message: res.error.message
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
@ -243,7 +245,15 @@ export function serializeActionResult(res: SafeResult<any, any>): SerializedActi
|
|||
|
||||
export function deserializeActionResult(res: SerializedActionResult): SafeResult<any, any> {
|
||||
if (res.type === 'error') {
|
||||
return { error: ActionError.fromJson(JSON.parse(res.body)), data: undefined };
|
||||
if (import.meta.env?.PROD) {
|
||||
return { error: ActionError.fromJson(JSON.parse(res.body)), data: undefined };
|
||||
} else {
|
||||
const error = ActionError.fromJson(JSON.parse(res.body));
|
||||
error.stack = actionResultErrorStack.get();
|
||||
return {
|
||||
error, data: undefined
|
||||
}
|
||||
}
|
||||
}
|
||||
if (res.type === 'empty') {
|
||||
return { data: undefined, error: undefined };
|
||||
|
@ -255,3 +265,16 @@ export function deserializeActionResult(res: SerializedActionResult): SafeResult
|
|||
error: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
// in-memory singleton to save the stack trace
|
||||
const actionResultErrorStack = function actionResultErrorStackFn() {
|
||||
let errorStack: string | undefined;
|
||||
return {
|
||||
set(stack: string | undefined) {
|
||||
errorStack = stack;
|
||||
},
|
||||
get() {
|
||||
return errorStack;
|
||||
}
|
||||
}
|
||||
}();
|
||||
|
|
Loading…
Reference in a new issue