WIP: Full restruct, seprate service and api
Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
@@ -13,12 +13,13 @@ import (
|
||||
// :5=original
|
||||
|
||||
type Builder struct {
|
||||
Status string
|
||||
Service string
|
||||
Endpoint string
|
||||
Type string
|
||||
Original string
|
||||
Error error
|
||||
Status string
|
||||
Service string
|
||||
Endpoint string
|
||||
Type string
|
||||
Original string
|
||||
Error error
|
||||
ErrorCode string
|
||||
}
|
||||
|
||||
func (self *Builder) SetStatus(s string) *Builder {
|
||||
@@ -51,16 +52,25 @@ func (self *Builder) SetError(e error) *Builder {
|
||||
return self
|
||||
}
|
||||
|
||||
func (self *Builder) Build(ctx context.Context) string {
|
||||
errorCode := fmt.Sprintf("%s%s%s%s%s",
|
||||
func (self *Builder) build() {
|
||||
self.ErrorCode = fmt.Sprintf("%s%s%s%s%s",
|
||||
self.Status,
|
||||
self.Service,
|
||||
self.Endpoint,
|
||||
self.Type,
|
||||
self.Original,
|
||||
)
|
||||
if self.Error != nil {
|
||||
ErrorHandler(ctx, self.Status, errorCode, self.Error)
|
||||
}
|
||||
return errorCode
|
||||
}
|
||||
|
||||
func (self *Builder) Throw(ctx *context.Context) *Builder {
|
||||
self.build()
|
||||
if self.Error != nil {
|
||||
ErrorHandler(ctx, self.Status, self.ErrorCode, self.Error)
|
||||
}
|
||||
return self
|
||||
}
|
||||
|
||||
func (self *Builder) String() string {
|
||||
self.build()
|
||||
return self.ErrorCode
|
||||
}
|
||||
|
||||
@@ -5,15 +5,15 @@ import (
|
||||
"log/slog"
|
||||
)
|
||||
|
||||
func ErrorHandler(ctx context.Context, status string, errorCode string, err error) {
|
||||
func ErrorHandler(ctx *context.Context, status string, errorCode string, err error) {
|
||||
switch status {
|
||||
case StatusSuccess:
|
||||
slog.InfoContext(ctx, "Service exception! ErrId: "+errorCode, "id", errorCode, "err", err)
|
||||
slog.InfoContext(*ctx, "Service exception! ErrId: "+errorCode, "id", errorCode, "err", err)
|
||||
case StatusUser:
|
||||
slog.WarnContext(ctx, "Service exception! ErrId: "+errorCode, "id", errorCode, "err", err)
|
||||
slog.WarnContext(*ctx, "Service exception! ErrId: "+errorCode, "id", errorCode, "err", err)
|
||||
case StatusServer:
|
||||
slog.ErrorContext(ctx, "Service exception! ErrId: "+errorCode, "id", errorCode, "err", err)
|
||||
slog.ErrorContext(*ctx, "Service exception! ErrId: "+errorCode, "id", errorCode, "err", err)
|
||||
case StatusClient:
|
||||
slog.ErrorContext(ctx, "Service exception! ErrId: "+errorCode, "id", errorCode, "err", err)
|
||||
slog.ErrorContext(*ctx, "Service exception! ErrId: "+errorCode, "id", errorCode, "err", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user