- modify type -> interface and import path, param name

This commit is contained in:
2021-12-30 14:32:45 +09:00
parent 0ebb2571c2
commit 0ea85b9246
6 changed files with 11 additions and 11 deletions

View File

@@ -1,8 +1,8 @@
import { merge } from 'lodash'
import type { AxiosError, AxiosInstance, AxiosRequestConfig, CancelTokenSource } from 'axios'
import axios from 'axios'
import { HTTP_METHODS } from '../../constants'
import { getError, parseResponse } from './parse'
import { HTTP_METHODS } from '~/constants'
import { config } from '~/configs'
import type { RequestOptions } from '~/types/models/requestOptions'
@@ -16,12 +16,12 @@ const axiosInstance = axios.create({
const axiosInstanceSource = CancelToken.source()
export function setAxiosRequestConfig(
api: AxiosInstance, source: CancelTokenSource, methodType: string, url: string, options?: RequestOptions,
api: AxiosInstance, { token: cancelToken }: CancelTokenSource, method: string, url: string, options?: RequestOptions,
) {
const requestConfig = merge({
url,
cancelToken: source.token,
method: methodType,
cancelToken,
method,
}, options)
// eslint-disable-next-line no-console
@@ -44,8 +44,8 @@ export function getHttpMethodsWithCancel(
source = axiosInstanceSource,
parse = parseResponse,
) {
const getApiPromise = (methodType: string, url: string, options?: RequestOptions) =>
setAxiosRequestConfig(api, source, methodType, url, options)
const getApiPromise = (method: string, url: string, options?: RequestOptions) =>
setAxiosRequestConfig(api, source, method, url, options)
.then(parse)
.catch((error: AxiosError) => {
getError(error)

View File

@@ -2,7 +2,7 @@ import type { AxiosError, AxiosResponse } from 'axios'
import {
ERROR_CODE,
HTTP_STATUS_CODE,
} from '../../constants'
} from '~/constants'
import type { ResponseModel } from '~/types/models/responseModel'
export const getError = (responseError: AxiosError) => {

View File

@@ -1,6 +1,6 @@
import type { HeroModel } from '~/types/models/heroModel'
export type HeroStateType = {
export interface HeroStateType {
heroes: HeroModel[]
hero: HeroModel
loading: boolean

View File

@@ -1,4 +1,4 @@
export type HeroModel = {
export interface HeroModel {
id: string
firstName: string
lastName: string

View File

@@ -1,5 +1,5 @@
// Example API Request Options
export type RequestOptions<D = any> = {
export interface RequestOptions<D = any> {
url: string
data?: D
params?: any

View File

@@ -1,5 +1,5 @@
// Example API Response Model
export type ResponseModel = {
export interface ResponseModel {
data?: any
success?: boolean
errorCode?: string