export const errorFormatter = error => {
  if (error && error.response.data.error) {
    const response = { config: error.config, ...error.response, ...error.response.data };
    // delete data to avoid confusion
    delete response.data;
    return response;
  }
  return error;
};

export const responseFormatter = response => {
  if (response.data.data) {
    return { ...response, ...response.data };
  }
  return response;
};

export const errorFormatter = error => {
  if (error && error.response.data.error) {
    const response = { config: error.config, ...error.response, ...error.response.data };
    // delete data to avoid confusion
    delete response.data;
    return response;
  }
  return error;
};

export const responseFormatter = response => {
  if (response && response.data && typeof response.data.data !== 'undefined') {
    return { ...response, ...response.data };
  }
  return response;
};

Fix gateway response formatter for falsy data
Fix gateway response formatter for falsy data

Sometimes the data response from the API is falsy. For example when
asking for a count, the count could be 0. This makes sure the data
is still formatted properly
