Skip to content

Commit d04a7be

Browse files
committed
Allow asking for rull response from http methods
1 parent eb509be commit d04a7be

File tree

1 file changed

+52
-20
lines changed

1 file changed

+52
-20
lines changed

http/index.ts

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -121,49 +121,81 @@ function addQueryParams(
121121

122122
async function getRequest<T>(
123123
accountId: number,
124-
options: HttpOptions
125-
): Promise<T> {
124+
options: HttpOptions,
125+
withFullResponse = false
126+
): Promise<T | AxiosResponse> {
126127
const { params, ...rest } = options;
127128
const axiosConfig = addQueryParams(rest, params);
128129
const configWithAuth = await withAuth(accountId, axiosConfig);
129-
const { data } = await axios<T>(configWithAuth);
130-
return data;
130+
131+
const response = await axios<T>(configWithAuth);
132+
133+
if (withFullResponse) {
134+
return response;
135+
}
136+
137+
return response.data;
131138
}
132139

133140
async function postRequest<T>(
134141
accountId: number,
135-
options: HttpOptions
136-
): Promise<T> {
142+
options: HttpOptions,
143+
withFullResponse = false
144+
): Promise<T | AxiosResponse> {
137145
const configWithAuth = await withAuth(accountId, options);
138-
const { data } = await axios({ ...configWithAuth, method: 'post' });
139-
return data;
146+
147+
const response = await axios({ ...configWithAuth, method: 'post' });
148+
149+
if (withFullResponse) {
150+
return response;
151+
}
152+
153+
return response.data;
140154
}
141155

142156
async function putRequest<T>(
143157
accountId: number,
144-
options: HttpOptions
145-
): Promise<T> {
158+
options: HttpOptions,
159+
withFullResponse = false
160+
): Promise<T | AxiosResponse> {
146161
const configWithAuth = await withAuth(accountId, options);
147-
const { data } = await axios({ ...configWithAuth, method: 'put' });
148-
return data;
162+
const response = await axios({ ...configWithAuth, method: 'put' });
163+
164+
if (withFullResponse) {
165+
return response;
166+
}
167+
168+
return response.data;
149169
}
150170

151171
async function patchRequest<T>(
152172
accountId: number,
153-
options: HttpOptions
154-
): Promise<T> {
173+
options: HttpOptions,
174+
withFullResponse = false
175+
): Promise<T | AxiosResponse> {
155176
const configWithAuth = await withAuth(accountId, options);
156-
const { data } = await axios({ ...configWithAuth, method: 'patch' });
157-
return data;
177+
const response = await axios({ ...configWithAuth, method: 'patch' });
178+
179+
if (withFullResponse) {
180+
return response;
181+
}
182+
183+
return response.data;
158184
}
159185

160186
async function deleteRequest<T>(
161187
accountId: number,
162-
options: HttpOptions
163-
): Promise<T> {
188+
options: HttpOptions,
189+
withFullResponse = false
190+
): Promise<T | AxiosResponse> {
164191
const configWithAuth = await withAuth(accountId, options);
165-
const { data } = await axios({ ...configWithAuth, method: 'delete' });
166-
return data;
192+
const response = await axios({ ...configWithAuth, method: 'delete' });
193+
194+
if (withFullResponse) {
195+
return response;
196+
}
197+
198+
return response.data;
167199
}
168200

169201
function createGetRequestStream(contentType: string) {

0 commit comments

Comments
 (0)