refactor: Add HTTP headers to API requests.
- Add headers to the fetch and refresh access token functions - Allow for optional headers in request data interface - Fix syntax error in headers object_literals in request method - Use default configuration instead of creating a new object in request method
This commit is contained in:
parent
8d0a054a44
commit
1aa0e1b6d0
@ -3,6 +3,7 @@ export interface IReqData {
|
||||
url: string
|
||||
method?: string
|
||||
data?: any
|
||||
headers?: any
|
||||
}
|
||||
export class NetClient {
|
||||
httpGet(reqData: IReqData | string): Promise<any> {
|
||||
@ -25,7 +26,7 @@ export class NetClient {
|
||||
async request(data: AxiosRequestConfig): Promise<any> {
|
||||
let defaultCfg: AxiosRequestConfig = {
|
||||
method: 'get',
|
||||
headers: {'Content-Type': 'application/json'}
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
}
|
||||
Object.assign(defaultCfg, data)
|
||||
console.log(defaultCfg)
|
||||
|
@ -18,6 +18,7 @@ export function fetchAccessToken(code: string) {
|
||||
return new NetClient().httpPost({
|
||||
url: url_access_token,
|
||||
method: 'post',
|
||||
headers: { 'Content-Type': 'text/html;' },
|
||||
})
|
||||
}
|
||||
|
||||
@ -29,5 +30,6 @@ export function refreshAccessToken(refresh_token: string) {
|
||||
return new NetClient().httpPost({
|
||||
url: url_refresh_token,
|
||||
method: 'post',
|
||||
headers: { 'Content-Type': 'text/html;' },
|
||||
})
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user