/*! * @license * Copyright Squiz Australia Pty Ltd. All Rights Reserved. */ import { AxiosResponse } from 'axios'; import { handleError } from './errorUtils'; /** * Handle axios response and extract data * @param axiosInstance - Promise resolving to axios response * @returns Response data */ export async function handleResponse(axiosInstance: Promise>): Promise { try { const response = await axiosInstance; if (response.status.toString().startsWith('2')) { return response.data; } throw handleError(response.data); } catch (error) { throw handleError(error); } } /** * Check if response is an axios response object * @param response - Response to check * @returns True if it's an axios response */ export function isAxiosResponse(response: any): boolean { return response instanceof Object && Object.prototype.hasOwnProperty.call(response, 'status'); }