adjust after getuk updated
This commit is contained in:
@@ -2,6 +2,7 @@ package libhelper
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
pl "simrs-vx/pkg/logger"
|
||||
"strings"
|
||||
"unicode"
|
||||
@@ -113,3 +114,54 @@ func HandleCreateError(input any, event *pl.Event, err error) error {
|
||||
return pl.SetLogError(event, input)
|
||||
}
|
||||
}
|
||||
|
||||
func HandleListError(input any, event *pl.Event, err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
e, ok := err.(*pgconn.PgError)
|
||||
if !ok {
|
||||
// fallback if it's not a pg error
|
||||
event.Status = "failed"
|
||||
event.ErrInfo = pl.ErrorInfo{
|
||||
Code: "data-list-fail",
|
||||
Detail: fmt.Sprintf("database list failed: %s", err.Error()),
|
||||
Raw: err,
|
||||
}
|
||||
return pl.SetLogError(event, input)
|
||||
}
|
||||
|
||||
re := regexp.MustCompile(`^([^:]+):\s*unsupported relations for schema\s+(\S+)`)
|
||||
if matches := re.FindStringSubmatch(e.Message); len(matches) == 3 {
|
||||
relation := strings.TrimSpace(matches[1])
|
||||
schema := strings.TrimSpace(matches[2])
|
||||
|
||||
event.Status = "failed"
|
||||
event.ErrInfo = pl.ErrorInfo{
|
||||
Code: "invalid-relation",
|
||||
Detail: fmt.Sprintf("Invalid relation '%s' for schema '%s' — check the relation name.", relation, schema),
|
||||
Raw: e,
|
||||
}
|
||||
return pl.SetLogError(event, input)
|
||||
}
|
||||
|
||||
if strings.Contains(e.Message, "unsupported relations for schema") {
|
||||
event.Status = "failed"
|
||||
event.ErrInfo = pl.ErrorInfo{
|
||||
Code: "invalid-relation",
|
||||
Detail: fmt.Sprintf("Unsupported relation detected: %s", e.Message),
|
||||
Raw: e,
|
||||
}
|
||||
return pl.SetLogError(event, input)
|
||||
}
|
||||
|
||||
// Generic pg error fallback
|
||||
event.Status = "failed"
|
||||
event.ErrInfo = pl.ErrorInfo{
|
||||
Code: "pg-error",
|
||||
Detail: fmt.Sprintf("PostgreSQL error: %s", e.Message),
|
||||
Raw: e,
|
||||
}
|
||||
return pl.SetLogError(event, input)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user