Unify fallback and unimplemented API error handling

- 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>
This commit is contained in:
2026-06-06 17:13:27 +08:00
parent f6466989c6
commit 0dd5df0302
35 changed files with 149 additions and 72 deletions
+15 -2
View File
@@ -1,7 +1,7 @@
package api
import (
"fmt"
"honoka-chan/internal/constant"
"honoka-chan/internal/handler/api/album"
"honoka-chan/internal/handler/api/award"
"honoka-chan/internal/handler/api/background"
@@ -32,8 +32,10 @@ import (
"honoka-chan/internal/middleware"
"honoka-chan/internal/router"
apischema "honoka-chan/internal/schema/api"
commonschema "honoka-chan/internal/schema/common"
"honoka-chan/internal/session"
honokautils "honoka-chan/internal/utils"
"time"
"github.com/gin-gonic/gin"
)
@@ -108,9 +110,20 @@ func api(ctx *gin.Context) {
case "user":
result, err = user.UserApi(ctx, v.Action)
default:
err = fmt.Errorf("unimplemented api module: %s", v.Module)
err = honokautils.NewUnimplementedModuleError(v.Module)
}
if honokautils.IsUnimplementedError(err) {
results = append(results, commonschema.ApiErrorResp{
Result: commonschema.ErrorData{
ErrorCode: constant.ErrorCodeUnknown,
},
Status: 600,
CommandNum: false,
TimeStamp: time.Now().Unix(),
})
continue
}
if ss.CheckErr(err) {
return
}