Wrap more errors

This commit is contained in:
2022-02-15 12:37:04 +00:00
parent 7a0c4a17a2
commit 74a53954de
3 changed files with 15 additions and 5 deletions

View File

@@ -2,6 +2,7 @@ package http
import (
"encoding/json"
"fmt"
"strings"
"time"
)
@@ -13,14 +14,19 @@ func (j *JSONDate) UnmarshalJSON(b []byte) error {
s := strings.Trim(string(b), "\"")
t, err := time.Parse("2006-01-02", s)
if err != nil {
return err
return fmt.Errorf("parse date: %w", err)
}
*j = JSONDate(t)
return nil
}
func (j JSONDate) MarshalJSON() ([]byte, error) {
return json.Marshal(time.Time(j))
result, err := json.Marshal(time.Time(j))
if err != nil {
return nil, fmt.Errorf("marshal date: %w", err)
}
return result, nil
}
// Maybe a Format function for printing your date