|
1 | 1 | import { HttpRequest } from 'simple-http-request-builder'; |
2 | | -import { FetchResponseHandler } from '../handler/FetchResponseHandlers'; |
3 | 2 | import { toJsonResponse } from '../handler/ResponseJsonHandler'; |
4 | | -import { validateContentType } from '../handler/ValidateContentTypeHandler'; |
5 | | -import { fetchClient } from './FetchClient'; |
6 | 3 | import { validateBasicStatusCodes } from '../handler/ValidateBasicStatusCodeHandler'; |
| 4 | +import { jsonContentTypeValidator } from '../handler/ValidateContentTypeHandler'; |
| 5 | +import { fetchClient } from './FetchClient'; |
7 | 6 | import { HttpResponse } from './HttpResponse'; |
8 | 7 |
|
9 | | -/** |
10 | | - * A {@link FetchResponseHandler} that verify that the content type of a {@link Response} is JSON |
11 | | - * using the `content-type` response HTTP header. |
12 | | - * |
13 | | - * See {@link validateContentType} for the content type validation. |
14 | | - * |
15 | | - * @param response The {@link Response} to validate |
16 | | - */ |
17 | | -export const jsonContentTypeValidator: FetchResponseHandler = ( |
18 | | - response: Response, |
19 | | -) => validateContentType(response, 'json'); |
20 | | - |
21 | 8 | /** |
22 | 9 | * A {@link HttpClient} that executes an {@link HttpRequest} that returns JSON responses. |
23 | 10 | * It uses {@link fetchClient} to executes the {@link HttpRequest}, and then it uses the following handlers: |
24 | 11 | * 1. {@link validateBasicStatusCodes} |
25 | 12 | * 2. {@link jsonContentTypeValidator} |
26 | 13 | * 3. {@link toJsonResponse} |
27 | 14 | */ |
| 15 | +// eslint-disable-next-line import/prefer-default-export |
28 | 16 | export const defaultJsonFetchClient = <T>(httpRequest: HttpRequest<unknown>) |
29 | 17 | : Promise<HttpResponse<T>> => fetchClient( |
30 | 18 | httpRequest, validateBasicStatusCodes, jsonContentTypeValidator, toJsonResponse, |
|
0 commit comments