Skip to content

Commit 8413c5e

Browse files
committed
Return Promise<String>
1 parent 1589b18 commit 8413c5e

File tree

4 files changed

+8
-13
lines changed

4 files changed

+8
-13
lines changed

src/helpers/getJsonResponse.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
*/
1919

2020
import Resource from "../services/resource";
21-
import HttpClientException from "../httpClient/httpClientException";
22-
import ApiException from "../services/exception/apiException";
2321
import { IRequest } from "../typings/requestOptions";
2422

2523
async function getJsonResponse<T>(resource: Resource, jsonRequest: T | string, requestOptions?: IRequest.Options): Promise<string>;
@@ -29,7 +27,7 @@ async function getJsonResponse<T, R>(
2927
resource: Resource,
3028
jsonRequest: T | string,
3129
requestOptions: IRequest.Options = {},
32-
): Promise<R | string | HttpClientException | ApiException> {
30+
): Promise<R | string> {
3331
const request = typeof jsonRequest === "string" ? jsonRequest : JSON.stringify(jsonRequest);
3432
const response = await resource.request(request, requestOptions);
3533
try {

src/httpClient/clientInterface.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,14 @@
1717
* See the LICENSE file for more info.
1818
*/
1919
import { AgentOptions } from "https";
20-
import HttpClientException from "./httpClientException";
21-
import ApiException from "../services/exception/apiException";
2220
import { Config } from "../index";
2321
import { IRequest } from "../typings/requestOptions";
2422

2523
interface ClientInterface {
2624
request(
2725
endpoint: string, json: string, config: Config, isApiKeyRequired: boolean, requestOptions?: IRequest.Options,
28-
): Promise<string | HttpClientException | ApiException>;
29-
post(endpoint: string, postParameters: [string, string][], config: Config): Promise<HttpClientException | string>;
26+
): Promise<string>;
27+
post(endpoint: string, postParameters: [string, string][], config: Config): Promise<string>;
3028
proxy?: AgentOptions;
3129
}
3230

src/httpClient/httpURLConnectionClient.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class HttpURLConnectionClient implements ClientInterface {
4242
public request(
4343
endpoint: string, json: string, config: Config, isApiRequired: boolean,
4444
requestOptions: IRequest.Options,
45-
): Promise<string | HttpClientException | ApiException> {
45+
): Promise<string> {
4646
requestOptions.headers ??= {};
4747
requestOptions.timeout = config.connectionTimeoutMillis;
4848

@@ -71,7 +71,7 @@ class HttpURLConnectionClient implements ClientInterface {
7171
return this.doPostRequest(httpConnection, json);
7272
}
7373

74-
public post(endpoint: string, postParameters: [string, string][], config: Config): Promise<HttpClientException | string> {
74+
public post(endpoint: string, postParameters: [string, string][], config: Config): Promise<string> {
7575
const postQuery: string = this.getQuery(postParameters);
7676
const connectionRequest: ClientRequest = this.createRequest(endpoint, {}, config.applicationName);
7777
return this.doPostRequest(connectionRequest, postQuery);
@@ -133,7 +133,7 @@ class HttpURLConnectionClient implements ClientInterface {
133133
return params.map(([key, value]): string => `${key}=${value}`).join("&");
134134
}
135135

136-
private doPostRequest(connectionRequest: ClientRequest, json: string): Promise<HttpClientException | string> {
136+
private doPostRequest(connectionRequest: ClientRequest, json: string): Promise<string> {
137137
return new Promise((resolve, reject): void => {
138138
connectionRequest.flushHeaders();
139139

@@ -176,6 +176,7 @@ class HttpURLConnectionClient implements ClientInterface {
176176
errorCode: formattedData.errorCode,
177177
responseHeaders: res.headers,
178178
responseBody: response.body,
179+
apiError: formattedData,
179180
});
180181
} else if (isRequestError) {
181182
exception = new Error(response.body);

src/services/resource.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
import Config from "../config";
2121
import Service from "../service";
22-
import HttpClientException from "../httpClient/httpClientException";
23-
import ApiException from "./exception/apiException";
2422
import ClientInterface from "../httpClient/clientInterface";
2523
import { IRequest } from "../typings/requestOptions";
2624

@@ -33,7 +31,7 @@ class Resource {
3331
this.endpoint = endpoint;
3432
}
3533

36-
public request(json: string, requestOptions?: IRequest.Options): Promise<string | HttpClientException | ApiException> {
34+
public request(json: string, requestOptions?: IRequest.Options): Promise<string> {
3735
const clientInterface: ClientInterface = this.service.client.httpClient;
3836
const config: Config = this.service.client.config;
3937

0 commit comments

Comments
 (0)