Format builds an error Response body describing err by consulting the f.Errors lookup table. If no entry is found, it returns f.Default.
(err error)
| 43 | // Format builds an error Response body describing err by consulting |
| 44 | // the f.Errors lookup table. If no entry is found, it returns f.Default. |
| 45 | func (f Formatter) Format(err error) (body Response) { |
| 46 | root := errors.Root(err) |
| 47 | // Some types cannot be used as map keys, for example slices. |
| 48 | // If an error's underlying type is one of these, don't panic. |
| 49 | // Just treat it like any other missing entry. |
| 50 | defer func() { |
| 51 | if err := recover(); err != nil { |
| 52 | body = Response{f.Default, "", nil, true} |
| 53 | } |
| 54 | }() |
| 55 | info, ok := f.Errors[root] |
| 56 | if !ok { |
| 57 | info = f.Default |
| 58 | } |
| 59 | |
| 60 | body = Response{ |
| 61 | Info: info, |
| 62 | Detail: errors.Detail(err), |
| 63 | Data: errors.Data(err), |
| 64 | Temporary: f.IsTemporary(info, err), |
| 65 | } |
| 66 | return body |
| 67 | } |
| 68 | |
| 69 | // Write writes a json encoded Response to the ResponseWriter. |
| 70 | // It uses the status code associated with the error. |
no outgoing calls