Add error handling

This commit is contained in:
Tim
2021-07-05 04:37:28 +02:00
parent 7ec967a08b
commit 9fbdd98bc6
2 changed files with 21 additions and 5 deletions

View File

@@ -41,8 +41,11 @@ export default class PerudoApi {
});
}
private get<T = any>(url: string, getParameters?: Record<string, any>) {
private get<T extends ApiObject>(url: string, getParameters?: Record<string, any>): AxiosPromise<T> {
return axios.get(url).then((response: AxiosResponse<T>) => {
if (response?.data?.errors?.length > 0) {
throw response.data.errors?.join();
}
return response;
})
}