package navicat import "fmt" // Error is a tunnel-layer or remote MySQL error. It never includes passwords or tokens. type Error struct { Kind string // http, tunnel, mysql HTTPStatus int Errno uint32 Message string } func (e *Error) Error() string { if e == nil { return "" } msg := e.Message if msg == "" { msg = "unknown error" } switch e.Kind { case "http": if e.HTTPStatus != 0 { return fmt.Sprintf("tunnel http %d: %s", e.HTTPStatus, msg) } return "tunnel http: " + msg case "mysql": return fmt.Sprintf("mysql errno %d: %s", e.Errno, msg) default: return fmtErrno(e.Errno, msg) } } func headerError(h Header, httpStatus int) *Error { kind := "tunnel" switch h.Errno { case ErrnoUnsupportedPHP, ErrnoInvalidParams, ErrnoMySQLMissing, ErrnoInvalidToken: kind = "tunnel" default: if h.Errno > 0 { kind = "mysql" } } return &Error{Kind: kind, HTTPStatus: httpStatus, Errno: h.Errno, Message: h.Message} }