import logger from '@/utils/logger';
/**
 *
 * @param {*} response
 * @returns
 */
export const requestResponseHandler = async (response) => {
  try {
    const body = await response?.json();
    if (response.ok) {
      return body;
    }

    // Throw an error with the JSON body containing the form errors
    const error = new Error(body?.errorMessage || 'Une erreur est survenue');
    error.details = body;
    error.response = response;
    throw error;
  } catch (error) {
    logger.error('Une erreur est survenue lors du traitement de la réponse', {
      error,
      response,
    });
    throw error;
  }
};
export const errorHandler = (error) => {
  logger.error('Error:', { error });
  // Handle the error here, e.g., show a notification
  throw error;
};
