-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
Showing
10 changed files
with
64 additions
and
208 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 was deleted.
Oops, something went wrong.
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,4 +1,6 @@ | ||
import ExampleService from './exampleService' | ||
import { httpService } from '@/services' | ||
import createService from '@/services/createService' | ||
|
||
export const exampleService = new ExampleService(httpService) | ||
export const exampleService = createService( | ||
String(import.meta.env.VITE_API_URL), | ||
Number(import.meta.env.VITE_TIMEOUT), | ||
) |
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
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
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { extend } from 'umi-request' | ||
|
||
function createService( | ||
baseUrl: string, | ||
timeout: number, | ||
) { | ||
const STATUS_CODES = { | ||
401: 'Unauthorized', | ||
404: 'Page not found', | ||
} | ||
|
||
const request = extend({ | ||
prefix: baseUrl, | ||
timeout, | ||
errorHandler(error) { | ||
if (error.response) { | ||
/** | ||
* DESC: | ||
* the request was made and the server responded with a status code | ||
* that falls out of the range of 2xx | ||
*/ | ||
console.error(STATUS_CODES[error.response.status]) | ||
} | ||
else { | ||
/** | ||
* DESC: | ||
* the request was made but no response was received | ||
* or error occurs when setting up the request. | ||
*/ | ||
console.error(error.message) | ||
} | ||
|
||
return error | ||
}, | ||
}) | ||
|
||
request.interceptors.response.use((response) => { | ||
return response | ||
}) | ||
|
||
return request | ||
} | ||
|
||
export default createService |
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,6 +1,6 @@ | ||
import Http from './Http' | ||
import createService from './createService' | ||
|
||
export const httpService = new Http({ | ||
baseURL: import.meta.env.VITE_API_URL, | ||
timeout: Number(import.meta.env.VITE_TIMEOUT), | ||
}) | ||
export const httpService = createService( | ||
String(import.meta.env.VITE_API_URL), | ||
Number(import.meta.env.VITE_TIMEOUT), | ||
) |