src/interceptors/response-interceptor.ts   A
last analyzed

Complexity

Total Complexity 2
Complexity/F 1

Size

Lines of Code 58
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 20
mnd 0
bc 0
fnc 2
dl 0
loc 58
rs 10
bpm 0
cpm 1
noi 0
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A ResponseInterceptor.responseHandler 0 6 1
A ResponseInterceptor.errorHandler 0 6 1
1
import { BEditaApiClient, BEditaClientResponse } from '../bedita-api-client';
2
import { AxiosResponse } from 'axios';
3
4
/**
5
 * Interface for a Response interceptor
6
 */
7
export interface ResponseInterceptorInterface {
8
9
    /**
10
     * The response handler called on request success.
11
     * Useful for edit data before return response.
12
     *
13
     * @param config The request configuration
14
     */
15
    responseHandler(response: AxiosResponse): AxiosResponse<any> | Promise<AxiosResponse<any>>;
16
17
    /**
18
     * The error handler called if something goes wrong.
19
     *
20
     * @param error The axios error
21
     */
22
    errorHandler(error: any): Promise<any>;
23
}
24
25
/**
26
 * Base class to implement response interceptors.
27
 */
28
export default abstract class ResponseInterceptor implements ResponseInterceptorInterface {
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 responseHandler(response: AxiosResponse): Promise<BEditaClientResponse<any> | AxiosResponse<any>> {
48
        return Promise.resolve(response);
49
    }
50
51
    /**
52
     * @inheritdoc
53
     */
54
    public errorHandler(error: any): Promise<any> {
55
        return Promise.reject(error);
56
    }
57
}
58