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
+11 -4
View File
@@ -101,7 +101,9 @@ export class PortalApiError extends Error {
? 'O registo solicitado já não está disponível.'
: status === 422
? 'Verifique os campos assinalados.'
: 'Não foi possível comunicar com o portal. Tente novamente.',
: status === 419
? 'A sessão não pôde ser validada. Actualize a página e tente novamente.'
: 'Não foi possível comunicar com o portal. Tente novamente.',
);
this.status = status;
this.errors = errors;
@@ -122,10 +124,15 @@ export async function portalRequest<T>(
typeof document === 'undefined'
? undefined
: document.cookie
.split('; ')
.split(';')
.map((value) => value.trim())
.find((value) => value.startsWith('XSRF-TOKEN='))
?.slice(11);
if (token) headers.set('X-XSRF-TOKEN', decodeURIComponent(token));
try {
if (token) headers.set('X-XSRF-TOKEN', decodeURIComponent(token));
} catch {
throw new PortalApiError(419);
}
}
const response = await fetch(url, {
...options,
@@ -136,7 +143,7 @@ export async function portalRequest<T>(
if (!response.ok || body === null) {
throw new PortalApiError(
response.status,
response.status === 422 ? body?.errors : undefined,
response.status === 422 ? (body?.errors ?? {}) : undefined,
);
}
return body as T;