Created
July 12, 2019 03:29
-
-
Save kaueDM/3c3a9ebdf74c3a26215d7c9eda7c1546 to your computer and use it in GitHub Desktop.
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
import axios from 'axios' | |
import throwError from './throwError' | |
import { inbound, outbound } from './interceptors' | |
import { GetPublicResourceInterface } from './Interfaces' | |
const getPublicResource = async (props: GetPublicResourceInterface) => { | |
const { endpoint, method, data, params, headers } = props | |
const API_URL = 'https://some.url.here/v1' | |
const url = `${API_URL}${endpoint}` | |
try { | |
axios.interceptors.request.use((request: any) => outbound(request)) | |
axios.interceptors.response.use((response: any) => inbound(response)) | |
return axios.request({ url, method, data, params, headers }) | |
.catch((error) => { | |
console.table(throwError(error)) | |
return throwError(error) | |
}) | |
} catch (error) { | |
console.error('Application error:') | |
return console.table(throwError(error)) | |
} | |
} | |
export default getPublicResource |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment