parseApiError.tsx 324 B

1234567891011121314
  1. export default function parseApiError(resp: JQueryXHR): string {
  2. const {detail} = (resp && resp.responseJSON) || ({} as object);
  3. // return immediately if string
  4. if (typeof detail === 'string') {
  5. return detail;
  6. }
  7. if (detail && detail.message) {
  8. return detail.message;
  9. }
  10. return 'Unknown API Error';
  11. }