mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-02-28 20:56:42 +00:00
Ensured JSON decodedoes not happen for endpoints returning empty body
This commit is contained in:
@@ -5,13 +5,15 @@ export class HttpClient {
|
||||
|
||||
public fetchJson<T>(url: string, options?: RequestInit): Promise<T> {
|
||||
return this.fetch(url, options).then(async (resp) => {
|
||||
const parsed = await resp.json();
|
||||
|
||||
if (!resp.ok) {
|
||||
throw parsed;
|
||||
throw await resp.json();
|
||||
}
|
||||
|
||||
return parsed as T;
|
||||
try {
|
||||
return (await resp.json()) as T;
|
||||
} catch (e) {
|
||||
return undefined as T;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user