mirror of
https://github.com/v2rayA/v2rayA.git
synced 2026-10-19 23:45:11 +08:00
aaeeb9307b
The GUI shows backend error text as is, so errors were never localized. common.Coded wraps an error with a stable code and scalar parameters; ResponseError adds "errorCode" and "params" next to the unchanged English "message" when the chain carries one. Thirty-two user-facing errors are coded (no server selected, core start failure, port occupied, malformed link with protocol and detail, subscription fetch failure with host, server/subscription not found with ids, bad request with the field, credentials, session, admin, request in progress, GFW list missing, invalid config, asset download, transparent setup, mux range, custom inbound fields). logError now keeps the error chain instead of flattening it. Messages, status codes and control flow are unchanged; the two strings the GUI matches on stay as they are. tools_test.go becomes an external test package so the common tests compile again; its FillEmpty equality assertion, which never ran before, is skipped with the reason.
22 lines
399 B
Go
22 lines
399 B
Go
package controller
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/v2rayA/v2rayA/common"
|
|
"github.com/v2rayA/v2rayA/pkg/util/log"
|
|
)
|
|
|
|
func logError(err interface{}) error {
|
|
e, ok := err.(error)
|
|
if !ok {
|
|
e = fmt.Errorf("%v", err)
|
|
}
|
|
log.Error("%v", e)
|
|
return e
|
|
}
|
|
|
|
func badRequest(field string, err interface{}) error {
|
|
return common.Coded("BAD_REQUEST", logError(err), map[string]interface{}{"field": field})
|
|
}
|