Skip to content

Latest commit

 

History

History
36 lines (24 loc) · 1.06 KB

configured-axios-middleware-development-guide.md

File metadata and controls

36 lines (24 loc) · 1.06 KB

Configured axios middleware development guide

Introduction

This is the wrapper for redux-axios-middleware with our custom configuration, which will dispatch a FSA onError and onSuccess.

Usage

Simply using applyMiddleware in the real store:

import { createStore, applyMiddleware } from 'redux';

createStore(
  ...,
  applyMiddleware(thunk, configuredAxiosMiddleware)
  ...
);

or using in mock store like this:

import configureMockStore from 'redux-mock-store';

const middlewares = [configuredAxiosMiddleware];
const mockStore = configureMockStore(middlewares);

const store = mockStore();

also we provide the getErrorMessage which simply return error message when the API return status code out of range [200~299]. So you can use it when writing test for some async action. Source code:

export const getErrorMessage = (url, status) => (`Request to ${url} failed with status code ${status}.`);