commit16
This commit is contained in:
@@ -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}).`,
|
||||
|
||||
Reference in New Issue
Block a user