@apigames/rest-client
Advanced tools
Comparing version 22.1.0-dev.7 to 22.1.0-dev.8
import { IRestClient, RestClientOptions, RestClientResponse } from '..'; | ||
export default class RestClient implements IRestClient { | ||
private HandleError; | ||
private IsAxiosError; | ||
private PrepareRequestConfig; | ||
private ProcessError; | ||
private ProcessResponse; | ||
@@ -7,0 +7,0 @@ Delete(uri: string, headers?: Record<string, string>, options?: RestClientOptions): Promise<RestClientResponse>; |
@@ -19,15 +19,2 @@ "use strict"; | ||
class RestClient { | ||
HandleError(uri, response) { | ||
if ((0, json_1.isDefinedAndNotNull)(response)) { | ||
(0, __1.ThrowException)({ | ||
statusCode: response.status, | ||
statusText: response.statusText, | ||
headers: response.headers, | ||
data: response.data, | ||
}); | ||
} | ||
else { | ||
(0, __1.ThrowNetworkConnectionException)(uri); | ||
} | ||
} | ||
IsAxiosError(error) { | ||
@@ -50,2 +37,20 @@ return error.isAxiosError !== undefined; | ||
} | ||
ProcessError(uri, error) { | ||
if (this.IsAxiosError(error)) { | ||
if ((0, json_1.isDefinedAndNotNull)(error.response)) { | ||
(0, __1.ThrowException)({ | ||
statusCode: error.response.status, | ||
statusText: error.response.statusText, | ||
headers: error.response.headers, | ||
data: error.response.data, | ||
}); | ||
} | ||
else { | ||
(0, __1.ThrowNetworkConnectionException)(uri); | ||
} | ||
} | ||
else { | ||
throw error; | ||
} | ||
} | ||
ProcessResponse(axiosResponse) { | ||
@@ -65,8 +70,3 @@ return { | ||
catch (error) { | ||
if (this.IsAxiosError(error)) { | ||
this.HandleError(uri, error.response); | ||
} | ||
else { | ||
throw error; | ||
} | ||
this.ProcessError(uri, error); | ||
} | ||
@@ -81,8 +81,3 @@ }); | ||
catch (error) { | ||
if (this.IsAxiosError(error)) { | ||
this.HandleError(uri, error.response); | ||
} | ||
else { | ||
throw error; | ||
} | ||
this.ProcessError(uri, error); | ||
} | ||
@@ -97,8 +92,3 @@ }); | ||
catch (error) { | ||
if (this.IsAxiosError(error)) { | ||
this.HandleError(uri, error.response); | ||
} | ||
else { | ||
throw error; | ||
} | ||
this.ProcessError(uri, error); | ||
} | ||
@@ -113,8 +103,3 @@ }); | ||
catch (error) { | ||
if (this.IsAxiosError(error)) { | ||
this.HandleError(uri, error.response); | ||
} | ||
else { | ||
throw error; | ||
} | ||
this.ProcessError(uri, error); | ||
} | ||
@@ -129,8 +114,3 @@ }); | ||
catch (error) { | ||
if (this.IsAxiosError(error)) { | ||
this.HandleError(uri, error.response); | ||
} | ||
else { | ||
throw error; | ||
} | ||
this.ProcessError(uri, error); | ||
} | ||
@@ -145,8 +125,3 @@ }); | ||
catch (error) { | ||
if (this.IsAxiosError(error)) { | ||
this.HandleError(uri, error.response); | ||
} | ||
else { | ||
throw error; | ||
} | ||
this.ProcessError(uri, error); | ||
} | ||
@@ -153,0 +128,0 @@ }); |
@@ -6,3 +6,3 @@ { | ||
"license": "MIT", | ||
"version": "22.1.0-dev.7", | ||
"version": "22.1.0-dev.8", | ||
"main": "lib/index.js", | ||
@@ -9,0 +9,0 @@ "types": "lib/index.d.ts", |
94273
1554