package ero import "net/http" type Type int const ( // ServerError 通用的,不需要特殊处理暴露给前端的错误 ServerError Type = iota // FormError 表单校验异常,没有执行成功。Data 内会有明确的字段级错误返回给前端处理 FormError ) // GeneralError 通用的错误数据包装 type GeneralError struct { Status int // Type 错误类型,参考自定义类型 Type Type Type // Message 当前错误的简短解释 Message string // Data 如果是复杂错误,此处会返回前端协助前端展示错误的数据 Data any } func SimpleError(msg string) *GeneralError { return &GeneralError{http.StatusInternalServerError, ServerError, msg, nil} }