<commit_before>/* eslint-disable prettier/prettier */
const parseError = function(err, defaultMessage) {
  let errMsg = defaultMessage || '';
  if (err.errors && err.errors.length) {
    errMsg = err.errors[0].detail || errMsg;
  } else if (err.payload && err.payload.detail) {
    errMsg = err.payload.detail;
  } else if (err.message) {
    errMsg = err.message;
  }
  return errMsg;
};

export default parseError;<commit_msg>Refactor parse-error to handle adapter error, server error & few more scenarios<commit_after>export default function parseError(err, defaultMessage) {
  let errMsg = defaultMessage || '';
  let error;
  if (err.errors && err.errors.length) {
    error = err.errors[0];
  } else {
    error = err;
  }
  if (error.status == 500) {
    errMsg = error.title;
  } else if (error.status == 0) {
    errMsg = 'API request failed'; // adapter error
  } else if (error.payload && error.payload.detail) {
    errMsg = error.payload.detail;
  } else if (error.payload && error.payload.message) {
    errMsg = error.payload.message;
  } else if (error.detail) {
    errMsg = error.detail;
  } else if (error.message) {
    errMsg = error.message;
  } else if (error.title) {
    errMsg = error.title;
  }
  return errMsg;
}
{'fraction_non_alphanumeric': 0.13870967741935483, 'fraction_numerical': 0.004838709677419355, 'mean_word_length': 3.25, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1170958', 'n_tokens_mistral': 408, 'n_tokens_neox': 401, 'n_words': 103}