Files
Zakk aaeeb9307b feat(api): attach a machine-readable errorCode and params to FAIL responses
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.
2026-09-18 03:52:59 +10:00

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})
}