1- import axios from 'axios' ;
21import * as defaults from './defaults' ;
32import { handleError } from './error' ;
43
@@ -11,28 +10,42 @@ export default class Client {
1110 Authorization : `Bearer ${ apiKey } ` ,
1211 } ;
1312
14- this . connection = axios . create ( {
15- headers,
16- baseURL : `${ config . protocol } ://${ config . host } /${ config . apiVersion } /` ,
17- timeout : config . timeout * 1000 ,
18- } ) ;
13+ this . baseURL = `${ config . protocol } ://${ config . host } /${ config . apiVersion } /` ;
14+ this . timeout = config . timeout * 1000 ;
15+ this . headers = headers ;
1916 }
2017
2118 async get ( path ) {
2219 try {
23- const response = await this . connection . get ( path ) ;
20+ const response = await fetch ( this . baseURL + path , {
21+ headers : this . headers ,
22+ timeout : this . timeout ,
23+ } ) ;
2424
25- return response . data ;
25+ if ( ! response . ok ) {
26+ throw new Error ( await response . text ( ) ) ;
27+ }
28+
29+ return await response . json ( ) ;
2630 } catch ( e ) {
2731 return handleError ( e ) ;
2832 }
2933 }
3034
3135 async post ( path , data ) {
3236 try {
33- const response = await this . connection . post ( path , data ) ;
37+ const response = await fetch ( this . baseURL + path , {
38+ method : 'POST' ,
39+ headers : Object . assign ( this . headers , { 'Content-Type' : 'application/json' } ) ,
40+ body : JSON . stringify ( data ) ,
41+ timeout : this . timeout ,
42+ } ) ;
43+
44+ if ( ! response . ok ) {
45+ throw new Error ( await response . text ( ) ) ;
46+ }
3447
35- return response . data ;
48+ return await response . json ( ) ;
3649 } catch ( e ) {
3750 return handleError ( e ) ;
3851 }
0 commit comments