Total Complexity | 2 |
Complexity/F | 1 |
Lines of Code | 58 |
Function Count | 2 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import { AxiosRequestConfig } from 'axios'; |
||
2 | import { BEditaApiClient } from '../bedita-api-client'; |
||
3 | |||
4 | /** |
||
5 | * Interface for a Request interceptor |
||
6 | */ |
||
7 | export interface RequestInterceptorInterface { |
||
8 | |||
9 | /** |
||
10 | * The request handler called before the request is sent. |
||
11 | * Useful for modify request config before it is used for build the request. |
||
12 | * |
||
13 | * @param config The request configuration |
||
14 | */ |
||
15 | requestHandler(config: AxiosRequestConfig): AxiosRequestConfig | Promise<AxiosRequestConfig>; |
||
16 | |||
17 | /** |
||
18 | * The error handler called if something goes wrong before the request was sent. |
||
19 | * |
||
20 | * @param error The axios error |
||
21 | */ |
||
22 | errorHandler(error: any): Promise<any>; |
||
23 | } |
||
24 | |||
25 | /** |
||
26 | * Base class to implement request interceptors. |
||
27 | */ |
||
28 | export default abstract class RequestInterceptor implements RequestInterceptorInterface { |
||
29 | |||
30 | /** |
||
31 | * Keep the BEditaApiClient instance. |
||
32 | */ |
||
33 | protected beditaClient: BEditaApiClient; |
||
34 | |||
35 | /** |
||
36 | * Constructor. |
||
37 | * |
||
38 | * @param beditaClient The bedita api client |
||
39 | */ |
||
40 | constructor(beditaClient: BEditaApiClient) { |
||
41 | this.beditaClient = beditaClient; |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * @inheritdoc |
||
46 | */ |
||
47 | public requestHandler(config: AxiosRequestConfig): AxiosRequestConfig | Promise<AxiosRequestConfig> { |
||
48 | return config; |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * @inheritdoc |
||
53 | */ |
||
54 | public errorHandler(error: any): Promise<any> { |
||
55 | return Promise.reject(error); |
||
56 | } |
||
57 | } |
||
58 |