add error types define

This commit is contained in:
Yavolte 2025-03-31 11:18:33 +08:00
parent ac427e9134
commit b4ebbba30c
3 changed files with 41 additions and 19 deletions

View File

@ -4,11 +4,12 @@ import (
"context"
"embed"
"flag"
"git.nobla.cn/golang/kos/entry/cli"
"git.nobla.cn/golang/kos/entry/http"
httpkg "net/http"
"time"
"git.nobla.cn/golang/kos/entry/cli"
"git.nobla.cn/golang/kos/entry/http"
"git.nobla.cn/golang/kos"
)
@ -32,8 +33,8 @@ func (s *subServer) Start(ctx context.Context) (err error) {
kos.Command().Handle("/test", "test command", func(ctx *cli.Context) (err error) {
return ctx.Success([][]string{
[]string{"NAME", "AGE"},
[]string{"SSS", "aaa"},
{"NAME", "AGE"},
{"SSS", "aaa"},
})
})

View File

@ -1,19 +1,21 @@
package http
import "git.nobla.cn/golang/kos/pkg/types"
const (
ErrAccessDenied = 4003 //拒绝访问
ErrPermissionDenied = 4004 //没有权限
ErrIllegalRequest = 4005 //非法请求
ErrInvalidPayload = 4006 //请求数据无效
ErrResourceCreate = 4101 //资源创建失败
ErrResourceUpdate = 4102 //资源更新失败
ErrResourceDelete = 4103 //资源删除失败
ErrResourceNotFound = 4104 //资源未找到
ErrResourceEmpty = 4105 //资源为空
ErrResourceExpired = 4107 //资源已失效
ErrResourceUnavailable = 4108 //资源无法使用
ErrResourceLocked = 4109 //资源已被锁定
ErrServerUnreachable = 4201 //服务不可用
ErrTemporaryUnavailable = 4202 //临时性失败
ErrFatal = 4204 //致命错误
ErrAccessDenied = types.ErrAccessDenied //拒绝访问
ErrPermissionDenied = types.ErrPermissionDenied //没有权限
ErrIllegalRequest = types.ErrIllegalRequest //非法请求
ErrInvalidPayload = types.ErrInvalidPayload //请求数据无效
ErrResourceCreate = types.ErrResourceCreate //资源创建失败
ErrResourceUpdate = types.ErrResourceUpdate //资源更新失败
ErrResourceDelete = types.ErrResourceDelete //资源删除失败
ErrResourceNotFound = types.ErrResourceNotFound //资源未找到
ErrResourceEmpty = types.ErrResourceEmpty //资源为空
ErrResourceExpired = types.ErrResourceExpired //资源已失效
ErrResourceUnavailable = types.ErrResourceUnavailable //资源无法使用
ErrResourceLocked = types.ErrResourceLocked //资源已被锁定
ErrServerUnreachable = types.ErrServerUnreachable //服务不可用
ErrTemporaryUnavailable = types.ErrTemporaryUnavailable //临时性失败
ErrFatal = types.ErrFatal //致命错误
)

19
pkg/types/error.go 100644
View File

@ -0,0 +1,19 @@
package types
const (
ErrAccessDenied = 4003 //拒绝访问
ErrPermissionDenied = 4004 //没有权限
ErrIllegalRequest = 4005 //非法请求
ErrInvalidPayload = 4006 //请求数据无效
ErrResourceCreate = 4101 //资源创建失败
ErrResourceUpdate = 4102 //资源更新失败
ErrResourceDelete = 4103 //资源删除失败
ErrResourceNotFound = 4104 //资源未找到
ErrResourceEmpty = 4105 //资源为空
ErrResourceExpired = 4107 //资源已失效
ErrResourceUnavailable = 4108 //资源无法使用
ErrResourceLocked = 4109 //资源已被锁定
ErrServerUnreachable = 4201 //服务不可用
ErrTemporaryUnavailable = 4202 //临时性失败
ErrFatal = 4204 //致命错误
)