Skip to content
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.

Commit

Permalink
feat: errors casting
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphg6 committed Apr 19, 2022
1 parent d864465 commit 67f4932
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
5 changes: 2 additions & 3 deletions controllers/v1/evalHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,10 @@ func EvalHandler() gin.HandlerFunc {
return
}

// log.Print("Context:\n\t", ctx.GetEntries(), "\n\n")
// log.Print("Features:\n\t", result.GetFeatures(), "\n\n")
log.Debug("Context:\n\t", ctx.GetEntries(), "\n\n")
log.Debug("Features:\n\t", result.GetFeatures(), "\n\n")

c.JSON(http.StatusOK, result.GetFeatures())
//fmt.Fprintf(w, "%v", result)
}

}
13 changes: 12 additions & 1 deletion types/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,18 @@ func (c *Context) loadImpl(param string) interface{} {
if !c.Has("errors") {
c.Put("errors", NewTypedMap())
}
c.GetMap("errors").AddItem(param, r)
switch r := r.(type) {
case *log.Entry:
c.GetMap("errors").AddItem(param, r.Message)
case log.Entry:
c.GetMap("errors").AddItem(param, r.Message)
case string:
c.GetMap("errors").AddItem(param, r)
case error:
c.GetMap("errors").AddItem(param, r.Error())
default:
c.GetMap("errors").AddItem(param, fmt.Sprintf("%v", r))
}
}()
remote, ok := c.RemoteLoadeds[param]
if !ok {
Expand Down

0 comments on commit 67f4932

Please sign in to comment.