0
Fork 0
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:
Emanuele Stoppa 2024-08-13 15:47:12 +01:00 committed by GitHub
parent 315ec07e1b
commit c7bda4cd67
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 31 additions and 3 deletions

View 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.

View file

@ -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;
}
}
}();