Skip to content

Instantly share code, notes, and snippets.

@kaueDM
Created July 12, 2019 03:29
Show Gist options
  • Save kaueDM/3c3a9ebdf74c3a26215d7c9eda7c1546 to your computer and use it in GitHub Desktop.
Save kaueDM/3c3a9ebdf74c3a26215d7c9eda7c1546 to your computer and use it in GitHub Desktop.
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