-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adiciona o service de words #32
- Loading branch information
1 parent
95d8bc1
commit 3bbdb44
Showing
5 changed files
with
53 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { AxiosError } from "axios"; | ||
|
||
export const errorInterceptor = (error: AxiosError) => { | ||
if(error.message === 'Network Error'){ | ||
return Promise.reject(new Error('Erro de conexão.')); | ||
} | ||
|
||
if(error.response?.status === 500){ | ||
return Promise.reject(new Error('Erro de servidor.')); | ||
} | ||
|
||
return Promise.reject(error); | ||
} |
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,5 @@ | ||
import { AxiosResponse } from "axios"; | ||
|
||
export const responseInterceptor = (response: AxiosResponse) => { | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import axios from 'axios'; | ||
import { responseInterceptor } from './ResponseInterceptor'; | ||
import { errorInterceptor } from './ErrorInterceptor'; | ||
|
||
const Api = axios.create({ | ||
baseURL: 'http://localhost:8080' | ||
}); | ||
|
||
Api.interceptors.response.use( | ||
response => responseInterceptor(response), | ||
error => errorInterceptor(error) | ||
); | ||
|
||
export { Api }; |
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,20 @@ | ||
import { Api } from "../axios.config"; | ||
|
||
export interface IWord { | ||
id: number, | ||
word: String, | ||
translation: String, | ||
status: String | ||
} | ||
|
||
const updateStatus = async (id: number, wordStatus: string): Promise<void | Error> => { | ||
try { | ||
await Api.put(`/word/updateStatus?wordId=${id}&status=${wordStatus}`); | ||
} catch (error) { | ||
return new Error((error as { message: string }).message || 'Erro ao listar Gold List'); | ||
} | ||
}; | ||
|
||
export const WordsService = { | ||
updateStatus | ||
} |