This commit is contained in:
2026-11-02 20:31:15 +02:00
parent 8ddfa93f45
commit 1da273f1f3
131 changed files with 14802 additions and 526 deletions
+14 -7
View File
@@ -3,12 +3,19 @@ import type {
PreparationDocument,
} from '@/components/private-investment-preparation';
function csrfToken(): string {
return decodeURIComponent(
document.cookie
.split('; ')
.find((c) => c.startsWith('XSRF-TOKEN='))
?.slice('XSRF-TOKEN='.length) ?? '',
);
try {
return decodeURIComponent(
document.cookie
.split(';')
.map((value) => value.trim())
.find((c) => c.startsWith('XSRF-TOKEN='))
?.slice('XSRF-TOKEN='.length) ?? '',
);
} catch {
throw new Error(
'A sessão não pôde ser validada. Actualize a página e tente novamente.',
);
}
}
export type ContextDocument = {
resource_id: number;
@@ -185,7 +192,7 @@ export async function contextApi<T>(
...(serializedBody === undefined ? {} : { body: serializedBody }),
});
const data = await response.json().catch(() => null);
if (!response.ok)
if (!response.ok || data === null)
throw new Error(
data?.message ||
`Não foi possível recuperar ou guardar o contexto (HTTP ${response.status}).`,