shared.ts 727 B

12345678910111213141516171819202122232425262728
  1. import type { AxiosHeaderValue, AxiosResponse, InternalAxiosRequestConfig } from 'axios';
  2. export function getContentType(config: InternalAxiosRequestConfig) {
  3. const contentType: AxiosHeaderValue = config.headers?.['Content-Type'] || 'application/json';
  4. return contentType;
  5. }
  6. /**
  7. * check if http status is success
  8. *
  9. * @param status
  10. */
  11. export function isHttpSuccess(status: number) {
  12. const isSuccessCode = status >= 200 && status < 300;
  13. return isSuccessCode || status === 304;
  14. }
  15. /**
  16. * is response json
  17. *
  18. * @param response axios response
  19. */
  20. export function isResponseJson(response: AxiosResponse) {
  21. const { responseType } = response.config;
  22. return responseType === 'json' || responseType === undefined;
  23. }