import { ElMessage } from 'element-plus';

const errorMessage = (options) => {
  return ElMessage({
    type: "error",
    duration: 5 * 1e3,
    showClose: true,
    grouping: true,
    ...options,
    message: options?.message || "\u672A\u77E5\u9519\u8BEF"
  });
};
const responseErrorMessage = (error, options) => {
  if (error.config?.disableMessage) {
    return;
  }
  if (error.code === "ERR_CANCELED") {
    return Promise.reject(error);
  }
  const serviceMessage = (error?.response?.data?.message || error?.response?.data?.comment || error?.response?.data?.msg || error?.response?.data?.errMsg) ?? "";
  switch (error.response?.status) {
    case 400:
      return errorMessage({
        message: `400-\u5BA2\u6237\u7AEF\u9519\u8BEF\uFF0C\u8BF7\u6C42\u5931\u8D25\u3002${serviceMessage}
        \u63A5\u53E3\u5730\u5740\uFF1A${error.config?.url ?? ""}`,
        ...options
      });
    case 403:
      return errorMessage({
        message: `403-\u65E0\u6743\u8BBF\u95EE\u3002${serviceMessage}
        \u63A5\u53E3\u5730\u5740\uFF1A${error.config?.url ?? ""}`,
        ...options
      });
    case 404:
      return errorMessage({
        message: `404-\u65E0\u6548\u7684\u8BF7\u6C42\u3002${serviceMessage}
        \u63A5\u53E3\u5730\u5740\uFF1A${error.config?.url ?? ""}`,
        ...options
      });
    case 413:
      return errorMessage({
        message: `413-\u8BF7\u6C42\u5185\u5BB9\u8FC7\u5927\u3002${serviceMessage}
        \u63A5\u53E3\u5730\u5740\uFF1A${error.config?.url ?? ""}`,
        ...options
      });
    case 500:
      return errorMessage({
        message: `500-\u670D\u52A1\u5668\u5185\u90E8\u9519\u8BEFo(\u2565\uFE4F\u2565)o\u3002${serviceMessage}
        \u63A5\u53E3\u5730\u5740\uFF1A${error.config?.url ?? ""}`,
        ...options
      });
    case 502:
      return errorMessage({
        message: `502-\u7F51\u5173\u9519\u8BEF\u3002${serviceMessage}
        \u63A5\u53E3\u5730\u5740\uFF1A${error.config?.url ?? ""}`,
        ...options
      });
    case 504:
      return errorMessage({
        message: `504-\u7F51\u5173\u8D85\u65F6\u3002${serviceMessage}
        \u63A5\u53E3\u5730\u5740\uFF1A${error.config?.url ?? ""}`,
        ...options
      });
    default:
      break;
  }
  if (error.message.includes("timeout")) {
    errorMessage({
      duration: 10 * 1e3,
      message: `\u8BF7\u6C42\u8D85\u65F6\u3002${serviceMessage}
      \u63A5\u53E3\u5730\u5740\uFF1A${error.config?.url ?? ""}`,
      ...options
    });
  } else if (error.message.includes("Network Error")) {
    errorMessage({
      duration: 10 * 1e3,
      message: `\u7F51\u7EDC\u9519\u8BEF\u3002${serviceMessage}
      \u63A5\u53E3\u5730\u5740\uFF1A${error.config?.url ?? ""}`,
      ...options
    });
  } else {
    errorMessage({
      message: `${error.message}\u3002${serviceMessage}
      \u63A5\u53E3\u5730\u5740\uFF1A${error.config?.url ?? ""}`,
      ...options
    });
  }
};

export { errorMessage, responseErrorMessage };
//# sourceMappingURL=errorMessage.mjs.map
