aboutsummaryrefslogtreecommitdiff
path: root/Timeline/ClientApp/src/data/common.ts
blob: e2882a80076c6be315aff8ea8ac915509895a813 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { AxiosError } from 'axios';

export function extractStatusCode(error: AxiosError): number | null {
  const code = error.response && error.response.status;
  if (typeof code === 'number') {
    return code;
  } else {
    return null;
  }
}

export interface CommonErrorResponse {
  code: number;
  message: string;
}

export function extractErrorCode(error: AxiosError): number | null {
  const { response } = error as AxiosError<CommonErrorResponse>;
  const code = response && response.data && response.data.code;
  if (typeof code === 'number') {
    return code;
  } else {
    return null;
  }
}