Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | 1x 1x 1x 1x 1x 27x 1x | import {OlzApiEndpoint, OlzApiRequests, OlzApiResponses} from './generated_olz_api_types';
import {Api, ApiError} from 'php-typescript-api';
import {login} from '../../Components/Auth/OlzLoginModal/OlzLoginModal';
import {codeHref} from '../../Utils/constants';
import {getErrorOrThrow} from '../../Utils/generalUtils';
export class OlzApi extends Api<OlzApiEndpoint, OlzApiRequests, OlzApiResponses> {
public baseUrl = `${codeHref}api`;
public async getResult<T extends OlzApiEndpoint>(
endpoint: T,
request: OlzApiRequests[T],
): Promise<[Error, null] | [null, OlzApiResponses[T]]> {
try {
const response = await this.call(endpoint, request);
return [null, response];
} catch (unk: unknown) {
const err = getErrorOrThrow(unk);
return [err, null];
}
}
public async call<T extends OlzApiEndpoint>(
endpoint: T,
request: OlzApiRequests[T],
): Promise<OlzApiResponses[T]> {
try {
return await super.call(endpoint, request);
} catch (caught: unknown) {
if (caught instanceof ApiError) {
if (caught.status === 401 || caught.status === 403) {
await login({});
return super.call(endpoint, request);
}
}
throw caught;
}
}
}
export const olzApi = new OlzApi();
|