Finanzen-Anfrage: Dateien lesen (as: 'blob'), z. B. das PDF einer Auftragsbestätigung
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d2883018fc
commit
eaf9fce1bc
2 files changed
+83
-2
No files matched your search
@@ -9,13 +9,14 @@ export const SESSION_EXPIRED_TEXT = 'Anmeldung abgelaufen. Bitte neu anmelden.'
|
||||
const statusError = (message, status) => Object.assign(new Error(message), { status })
|
||||
|
||||
/**
|
||||
* request(path, { method, body }) -> geparstes JSON oder ein Error mit `status` (und bei 502 nach dem Festschreiben
|
||||
* request(path, { method, body, as }) -> geparstes JSON oder ein Error mit `status` (und bei 502 nach dem Festschreiben
|
||||
* `invoiceId` / `invoiceNumber`). Meldungen:
|
||||
* - fetch wirft (Netz, Portal aus): „Das Kundenportal ist gerade nicht erreichbar.“ (status 0)
|
||||
* - 502/503/504 ohne JSON-Antwort (Proxy-Fehlerseite): dieselbe Meldung (status = HTTP-Status)
|
||||
* - createJWT scheitert (Sitzung abgelaufen): „Anmeldung abgelaufen. Bitte neu anmelden.“ (status 401)
|
||||
* - sonst die Meldung des Portals (`error`), ohne sie „API-Fehler <Status>“
|
||||
* Das JWT wird 10 Minuten gecacht; bei 401 einmal mit frischem JWT wiederholt.
|
||||
* Mit `as: 'blob'` liefert eine erfolgreiche Antwort den rohen Inhalt (Blob); Fehler kommen weiter als Meldung des Portals.
|
||||
*/
|
||||
export function createFinanceRequest({ baseUrl, createJWT, fetchImpl = (...args) => globalThis.fetch(...args), now }) {
|
||||
// JWT 10 Min. gecacht (Appwrite begrenzt das Erzeugen pro Nutzer)
|
||||
@@ -39,7 +40,7 @@ export function createFinanceRequest({ baseUrl, createJWT, fetchImpl = (...args)
|
||||
}
|
||||
}
|
||||
|
||||
return async function request(path, { method = 'GET', body } = {}) {
|
||||
return async function request(path, { method = 'GET', body, as } = {}) {
|
||||
const res = await fetchWithRetry(jwtCache, (jwt) =>
|
||||
portalFetch(`${baseUrl}${path}`, {
|
||||
method,
|
||||
@@ -47,6 +48,8 @@ export function createFinanceRequest({ baseUrl, createJWT, fetchImpl = (...args)
|
||||
body: body === undefined ? undefined : JSON.stringify(body),
|
||||
})
|
||||
)
|
||||
// Dateien (z. B. das PDF einer Auftragsbestätigung) kommen roh; Fehlerantworten bleiben JSON mit Meldung
|
||||
if (as === 'blob' && res.ok) return res.blob()
|
||||
let data = null
|
||||
try {
|
||||
data = await res.json()
|
||||
|
||||
Reference in new issue
Block a user