import { ElMessage } from "element-plus";

export function responseHandle({
  code,
  message,
  logout,
  handler,
  error,
  responseCode = 1
}: {
  code: number;
  message: string;
  logout: any;
  handler: () => void;
  error?: () => void;
  responseCode?: number;
}) {
  const c = Number(code);
  if (c === responseCode) {
    handler();
  } else if (c > 100 && c < 140) {
    logout();
  } else {
    if (error) {
      error();
    } else {
      ElMessage.error(message);
    }
  }
}
