Skip to content

Instantly share code, notes, and snippets.

View gaonkar-adi's full-sized avatar
🏠
Working from home

Aditya Gaonkar gaonkar-adi

🏠
Working from home
View GitHub Profile
@gaonkar-adi
gaonkar-adi / constants.js
Created November 11, 2020 15:11
Constants File to pass error messages to API.js
module.exports = Object.freeze({
ACTION_UNAUTHORIZED: 'The user is unauthorized',
ACTION_NOT_FOUND: 'Resource Not Found',
ACTION_INTERNAL_SERVER: 'Internal Server Error',
ACTION_BAD_GATEWAY: 'Bad Gateway',
ACTION_SERVICE_UNAVAILABLE: 'The service is unavailable',
ACTION_REQUEST_TIMED_OUT: 'Request Timed Out',
ACTION_TOO_MANY: 'Too Many Requests',
ACTION_INSUFFICIENT_STORAGE: 'Insuffucient Storage',
});
@gaonkar-adi
gaonkar-adi / API.js
Last active November 11, 2020 15:40
React Axios Wrapper with Error Notifications
import axios from 'axios';
import { toast } from 'react-toastify';
import ConstantsList from './constants';
class API {
constructor() {
let service = axios.create({});
service.interceptors.response.use(this.handleSuccessResponse, this.handleErrorResponse);
this.service = service;
}