- Add a shared common error response schema and unknown error code for business-level fallbacks - Return business error payloads for router NoRoute and NoMethod fallbacks - Align the existing event list fallback response with the shared error structure - Introduce an explicit unimplemented API error type instead of relying on formatted strings - Make /api batch dispatch return per-item status 600 error entries for unimplemented modules and actions without failing the whole batch Signed-off-by: Sean Du <do4suki@gmail.com>
38 lines
716 B
Go
38 lines
716 B
Go
package honokautils
|
|
|
|
import "errors"
|
|
|
|
type UnimplementedError struct {
|
|
Kind string
|
|
Module string
|
|
Name string
|
|
}
|
|
|
|
func (e *UnimplementedError) Error() string {
|
|
if e == nil {
|
|
return "unimplemented"
|
|
}
|
|
return "unimplemented " + e.Kind + ": " + e.Module + ": " + e.Name
|
|
}
|
|
|
|
func NewUnimplementedModuleError(module string) error {
|
|
return &UnimplementedError{
|
|
Kind: "api module",
|
|
Module: module,
|
|
Name: module,
|
|
}
|
|
}
|
|
|
|
func NewUnimplementedActionError(module string, action string) error {
|
|
return &UnimplementedError{
|
|
Kind: "action",
|
|
Module: module,
|
|
Name: action,
|
|
}
|
|
}
|
|
|
|
func IsUnimplementedError(err error) bool {
|
|
var target *UnimplementedError
|
|
return err != nil && errors.As(err, &target)
|
|
}
|