mirror of
https://github.com/LemmyNet/lemmy-js-client.git
synced 2024-11-22 20:31:12 +00:00
Simplifying
This commit is contained in:
parent
5c26a3835a
commit
c5fb4b559e
1 changed files with 9 additions and 16 deletions
25
src/http.ts
25
src/http.ts
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue