Skip to content

Commit 2c4d7b4

Browse files
author
Hidetaka Okamoto
committed
Merge branch 'master' of github.com:getshifter/domain-cli
2 parents 5f5b2c4 + 9bf5d16 commit 2c4d7b4

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

src/share/abstract.command.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ export abstract class AbstractCommand extends Command {
1414
return new APIClientWithAuthService(accessToken, showVerbose, development)
1515
}
1616

17-
abstract async run(): Promise<void>
17+
abstract run(): Promise<void>
1818
}

src/share/api/api.service.ts

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable no-console */
2-
import axios, {AxiosInstance, AxiosRequestConfig, AxiosError} from 'axios'
2+
import axios, {AxiosInstance, AxiosRequestConfig, AxiosError, AxiosResponse} from 'axios'
33
/**
44
* GET Shifter API endpoint
55
* @param env
@@ -30,15 +30,42 @@ export class APIClientService {
3030
this.debugMode = debugMode
3131
}
3232

33+
protected _recordAxiosRequest(url: string, path: string, config?: AxiosRequestConfig, body?: object): void {
34+
if (!this.debugMode) return
35+
const request = Object.assign({}, {
36+
url, path, body,
37+
})
38+
console.log({
39+
request,
40+
})
41+
}
42+
43+
protected _recordAxiosResponse<Response = any>(result: AxiosResponse<Response>): void {
44+
if (!this.debugMode) return
45+
const _target = (() => {
46+
if (typeof result.data !== 'object') {
47+
return result.data
48+
}
49+
const data = Object.assign({}, result.data) as any
50+
Object.keys(data).forEach(key => {
51+
if (/Token/.test(key) && data[key]) data[key] = '=== SECRET ==='
52+
})
53+
return data
54+
})()
55+
console.log({
56+
result: _target,
57+
})
58+
}
59+
3360
public async post(path: string, body?: object, config?: AxiosRequestConfig) {
3461
return this._post(path, body, config)
3562
}
3663

3764
protected async _post(path: string, body?: object, config?: AxiosRequestConfig) {
3865
const url = pathJoin(this.endpoint, path)
39-
if (this.debugMode) console.log({url, path, body, config})
66+
this._recordAxiosRequest(url, path, config, body)
4067
const result = await axios.post(url, body, config)
41-
if (this.debugMode) console.log({result})
68+
this._recordAxiosResponse(result)
4269
return result.data
4370
}
4471

@@ -48,9 +75,9 @@ export class APIClientService {
4875

4976
protected async _get(path: string, config?: AxiosRequestConfig) {
5077
const url = pathJoin(this.endpoint, path)
51-
if (this.debugMode) console.log({url, path, config})
78+
this._recordAxiosRequest(url, path, config)
5279
const result = await axios.get(url, config)
53-
if (this.debugMode) console.log({result})
80+
this._recordAxiosResponse(result)
5481
return result.data
5582
}
5683

0 commit comments

Comments
 (0)