/**
 * 从错误对象中提取错误消息。
 */
export function readError(error: unknown, fallback: string): string {
  if (typeof error === 'object' && error && 'response' in error) {
    const response = (
      error as {
        response?: {
          data?: {
            message?: string
            error?: string
          }
        }
      }
    ).response
    return response?.data?.message || response?.data?.error || fallback
  }
  if (error instanceof Error) {
    return error.message || fallback
  }
  if (typeof error === 'string') {
    return error
  }
  return fallback
}
