mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-20 10:15:17 -04:00
use async and await (#62)
Use async and await instead of promise chains
This commit is contained in:
parent
11f01094b4
commit
a5af15b278
7 changed files with 92 additions and 80 deletions
|
@ -3,13 +3,13 @@ import {BackendConfigState} from "../redux/backend-config/types";
|
|||
import {expectResponseCode, getBackendUrl} from "../utils/apiUtils";
|
||||
|
||||
export const getBackendConfig = async () => {
|
||||
return fetch(getBackendUrl() + '/backend-config.json')
|
||||
.then(expectResponseCode())
|
||||
.then(response => response.json() as Promise<BackendConfigState>);
|
||||
const response = await fetch(getBackendUrl() + '/backend-config.json');
|
||||
expectResponseCode(response);
|
||||
return await response.json() as Promise<BackendConfigState>;
|
||||
}
|
||||
|
||||
export const getFrontendConfig = async () => {
|
||||
return fetch('config.json')
|
||||
.then(expectResponseCode())
|
||||
.then(response => response.json() as Promise<FrontendConfigState>);
|
||||
const response = await fetch('config.json');
|
||||
expectResponseCode(response)
|
||||
return await response.json() as Promise<FrontendConfigState>;
|
||||
}
|
|
@ -5,7 +5,7 @@ export const getMe = async () => {
|
|||
}
|
||||
|
||||
export const postEmailLogin = async (email: string, password: string) => {
|
||||
return fetch(getBackendUrl() + "/login", {
|
||||
const response = await fetch(getBackendUrl() + "/login", {
|
||||
method: 'POST',
|
||||
mode: 'cors',
|
||||
cache: 'no-cache',
|
||||
|
@ -19,13 +19,14 @@ export const postEmailLogin = async (email: string, password: string) => {
|
|||
email: email,
|
||||
password: password,
|
||||
})
|
||||
})
|
||||
.then(expectResponseCode())
|
||||
.then(response => response.json());
|
||||
});
|
||||
|
||||
expectResponseCode(response);
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
export const postLdapLogin = async (username: string, password: string) => {
|
||||
return fetch(getBackendUrl() + "/auth/ldap", {
|
||||
const response = await fetch(getBackendUrl() + "/auth/ldap", {
|
||||
method: 'POST',
|
||||
mode: 'cors',
|
||||
cache: 'no-cache',
|
||||
|
@ -40,12 +41,13 @@ export const postLdapLogin = async (username: string, password: string) => {
|
|||
password: password,
|
||||
})
|
||||
})
|
||||
.then(expectResponseCode())
|
||||
.then(response => response.json());
|
||||
|
||||
expectResponseCode(response)
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
export const postOpenIdLogin = async (openId: string) => {
|
||||
return fetch(getBackendUrl() + "/auth/openid", {
|
||||
const response = await fetch(getBackendUrl() + "/auth/openid", {
|
||||
method: 'POST',
|
||||
mode: 'cors',
|
||||
cache: 'no-cache',
|
||||
|
@ -59,6 +61,7 @@ export const postOpenIdLogin = async (openId: string) => {
|
|||
openId: openId
|
||||
})
|
||||
})
|
||||
.then(expectResponseCode())
|
||||
.then(response => response.json());
|
||||
|
||||
expectResponseCode(response)
|
||||
return await response.json();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue