feat (patient): add search
This commit is contained in:
@@ -52,6 +52,31 @@ func HandleReadError(err error, event *pl.Event, itemType string, id interface{}
|
||||
return pl.SetLogError(event, nil)
|
||||
}
|
||||
|
||||
func HandleSearchError(err error, event *pl.Event, itemType string, query interface{}, data any) error {
|
||||
if err == nil {
|
||||
pl.SetLogInfo(event, data, "complete")
|
||||
return nil
|
||||
}
|
||||
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
event.Status = "failed"
|
||||
event.ErrInfo = pl.ErrorInfo{
|
||||
Code: "data-notFound",
|
||||
Detail: fmt.Sprintf("%s with query '%v' not found", itemType, query),
|
||||
Raw: err,
|
||||
}
|
||||
} else {
|
||||
event.Status = "failed"
|
||||
event.ErrInfo = pl.ErrorInfo{
|
||||
Code: "data-search-fail",
|
||||
Detail: fmt.Sprintf("%s search failed", itemType),
|
||||
Raw: err,
|
||||
}
|
||||
}
|
||||
|
||||
return pl.SetLogError(event, nil)
|
||||
}
|
||||
|
||||
func GetMiddlewareErrorCode(mwType MWType) string {
|
||||
if strings.Contains(string(mwType), "Pre") {
|
||||
return "MW_PRE_FAILED"
|
||||
|
||||
Reference in New Issue
Block a user