import { AxiosError } from 'axios';

import { ResponseCode } from 'src/types/services';

export const isArticlesAccessDeniedError = (
  error: AxiosError<{ code?: string }>,
) => {
  const requestUrl = error.config?.url || '';

  return (
    error?.response?.status === 403 &&
    error?.response?.data?.code === ResponseCode.ACCESS_DENIED &&
    /^\/?articles\//.test(requestUrl)
  );
};

export const isGroupsAccessDeniedError = (
  error: AxiosError<{ code?: string }>,
) => {
  const requestUrl = error.config?.url || '';

  return (
    error?.response?.status === 403 &&
    error?.response?.data?.code === ResponseCode.ACCESS_DENIED &&
    /^\/?groups\//.test(requestUrl)
  );
};
