format error message using title and detail when model implements rfc7807
(status string, v interface{})
| 672 | |
| 673 | // format error message using title and detail when model implements rfc7807 |
| 674 | func formatErrorMessage(status string, v interface{}) string { |
| 675 | str := "" |
| 676 | metaValue := reflect.ValueOf(v).Elem() |
| 677 | |
| 678 | if metaValue.Kind() == reflect.Struct { |
| 679 | field := metaValue.FieldByName("Title") |
| 680 | if field != (reflect.Value{}) { |
| 681 | str = fmt.Sprintf("%s", field.Interface()) |
| 682 | } |
| 683 | |
| 684 | field = metaValue.FieldByName("Detail") |
| 685 | if field != (reflect.Value{}) { |
| 686 | str = fmt.Sprintf("%s (%s)", str, field.Interface()) |
| 687 | } |
| 688 | } |
| 689 | |
| 690 | return strings.TrimSpace(fmt.Sprintf("%s %s", status, str)) |
| 691 | } |
no test coverage detected