import { type AxiosError } from 'axios';

import { type ResponseError } from 'src/types/services';

export enum ErrorCodes {
  GENERIC = 'GENERIC',
  BAD_QUESTIONS = 'BAD_QUESTIONS',
}

export const getErrorCode = (error: AxiosError<ResponseError>) => {
  if (!error?.response?.data?.code) return ErrorCodes.GENERIC;
  if (!error?.response?.data?.message) return ErrorCodes.GENERIC;

  const { message } = error.response.data;

  if (message.includes('Bad questions for task with tag:'))
    return ErrorCodes.BAD_QUESTIONS;

  return ErrorCodes.GENERIC;
};
