Skip to content

Commit

Permalink
Change representation of DAS error on web form
Browse files Browse the repository at this point in the history
  • Loading branch information
vkuznet committed Nov 19, 2022
1 parent 5be4186 commit 428d734
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion web/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,29 @@ func PresentDataPlain(path string, dasquery dasql.DASQuery, data []mongo.DASReco
return out
}

// helper function to parse DBSError struct
func parseDBSError(dbsErr mongo.DASRecord) string {
var out string
var desc, mesg bool
if v, ok := dbsErr["reason"]; ok {
reason := fmt.Sprintf("%v", v)
for _, v := range strings.Split(reason, ":") {
if desc || mesg {
v := strings.Replace(v, " Function", "", -1)
v = strings.Replace(v, " Message", "", -1)
out = fmt.Sprintf("%s<br/>%s", out, v)
}
if strings.Contains(v, " Description") {
desc = true
}
if strings.Contains(v, " Message") {
mesg = true
}
}
}
return out
}

// PresentData represents DAS records for web UI
func PresentData(path string, dasquery dasql.DASQuery, data []mongo.DASRecord, pmap mongo.DASRecord, nres, startIdx, limit int, procTime time.Duration) string {
var out []string
Expand Down Expand Up @@ -466,8 +489,15 @@ func PresentData(path string, dasquery dasql.DASQuery, data []mongo.DASRecord, p
}
rec := elem.(mongo.DASRecord)
if v, ok := rec["error"]; ok && v != "" && key != "rules" {
erec := fmt.Sprintf("<b>Error:</b> <span %s>%v</span>", red, v)
estm := fmt.Sprintf("### %v of type %T", v, v)
// log.Println("### estm", estm)
switch t := v.(type) {
case mongo.DASRecord:
estm = parseDBSError(t)
}
erec := fmt.Sprintf("<b>Error:</b> <span %s>%v</span>", red, estm)
values = append(values, erec)
continue
}
for _, uir := range uiRows {
uirow := uir.(mongo.DASRecord)
Expand Down

0 comments on commit 428d734

Please sign in to comment.