mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-24 17:28:31 +02:00
refactor: improve error handling and response formatting in API
This commit is contained in:
@@ -26,6 +26,9 @@ type (
|
||||
FieldsBody []LogField
|
||||
ListBody []string
|
||||
MessageBody string
|
||||
ErrorBody struct {
|
||||
Error error
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -113,3 +116,15 @@ func (m MessageBody) Format(format *LogFormat) ([]byte, error) {
|
||||
}
|
||||
return nil, fmt.Errorf("unknown format: %v", format)
|
||||
}
|
||||
|
||||
func (e ErrorBody) Format(format *LogFormat) ([]byte, error) {
|
||||
switch format {
|
||||
case LogFormatRawJSON:
|
||||
return json.Marshal(e)
|
||||
case LogFormatPlain:
|
||||
return gperr.Plain(e.Error), nil
|
||||
case LogFormatMarkdown:
|
||||
return gperr.Markdown(e.Error), nil
|
||||
}
|
||||
return nil, fmt.Errorf("unknown format: %v", format)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user