Simplifying

This commit is contained in:
Dessalines 2023-05-29 19:07:06 -04:00
parent 5c26a3835a
commit c5fb4b559e

View file

@ -1295,21 +1295,15 @@ export class LemmyHttp {
endpoint: string,
form: BodyType
): Promise<ResponseType> {
let response: Response;
if (type_ === HttpType.Get) {
const getUrl = `${this.buildFullUrl(endpoint)}?${encodeGetParams(form)}`;
const response = await fetch(getUrl, {
response = await fetch(getUrl, {
method: HttpType.Get,
headers: this.headers,
});
const json = await response.json();
if (!response.ok) {
throw json["error"] ?? response.statusText;
}
return json;
} else {
const response = await fetch(this.buildFullUrl(endpoint), {
response = await fetch(this.buildFullUrl(endpoint), {
method: type_,
headers: {
"Content-Type": "application/json",
@ -1317,14 +1311,13 @@ export class LemmyHttp {
},
body: JSON.stringify(form),
});
const json = await response.json();
if (!response.ok) {
throw json["error"] ?? response.statusText;
}
return json;
}
const json = await response.json();
if (!response.ok) {
throw json["error"] ?? response.statusText;
}
return json;
}
}