-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6fc3047
commit 9d6d775
Showing
3 changed files
with
32 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,24 @@ | ||
import axios, { AxiosRequestConfig } from 'axios'; | ||
import { isPlainObject, every, isString } from 'lodash'; | ||
|
||
const defaultHeaders = { | ||
'Content-Type': 'application/json', | ||
}; | ||
|
||
export const request = async (params: AxiosRequestConfig) => { | ||
const instance = axios.create({ | ||
headers: defaultHeaders, | ||
}); | ||
|
||
// Check if user defined headers is an object and contains only string values | ||
if (params.headers) { | ||
if (!isPlainObject(params.headers) || !every(params.headers, isString)) { | ||
throw new Error('Headers specified in the config must be a plain object with string values.'); | ||
} | ||
} | ||
|
||
const instance = axios.create({ | ||
headers: { | ||
...defaultHeaders, | ||
...params.headers, | ||
}, | ||
}); | ||
|
||
const response = await instance.request(params); | ||
return response; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters