Passed
Push — master ( 4bbdb1...02a41e )
by Dmytro
01:31
created

utils.js ➔ _axiosError   A

Complexity

Conditions 1

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 13
rs 9.9
c 0
b 0
f 0
cc 1
1
import { URL } from 'url';
2
import { last } from 'myrmidon';
3
import createAxiosError from 'axios/lib/core/createError';
4
5
6
export function resolveUrl(base, relativeUrl) {
7
    const baseUrl = base ? new URL(base) : undefined;
8
    const absoluteUrl = new URL(relativeUrl, baseUrl);
9
10
    if (absoluteUrl.href === relativeUrl) {
11
        return new URL(absoluteUrl,  baseUrl);
12
    }
13
14
    const apiPrefix = last(baseUrl.pathname) === '/'
15
        ? baseUrl.pathname.slice(0, -1)
16
        : baseUrl.pathname;
17
18
    const relPath = apiPrefix
19
        ? apiPrefix + absoluteUrl.pathname
20
        : relativeUrl;
21
22
    return new URL(relPath,  baseUrl);
23
}
24
25
export function _axiosError(
26
    opts,
27
    { message, code },
28
    data
29
) {
30
    return createAxiosError(
31
        message,
32
        opts,
33
        code,
34
        {},
35
        { data }
36
    );
37
}
38