🐛 Return server errors as 500 when marking a day fails
Marking a day answered every error except an invalid day key with 422, including database errors. Only an invalid kind is a 422 now. Server errors are logged with their cause and answered with a generic message instead of the error text, which can contain SQL, and the timezone lookup logs at warn before it falls back to UTC.
This commit is contained in:
@@ -52,13 +52,24 @@ func settingsAt(tx core.App, owner, dayKey string) (*core.Record, error) {
|
||||
return rows[0], nil
|
||||
}
|
||||
|
||||
// location returns the timezone of the settings effective on dayKey, or UTC when
|
||||
// there are none or they cannot be read. A failed lookup is logged because UTC
|
||||
// is only a guess at what the owner meant.
|
||||
func location(tx core.App, owner, dayKey string) *time.Location {
|
||||
set, err := settingsAt(tx, owner, dayKey)
|
||||
if err != nil || set == nil {
|
||||
if err != nil {
|
||||
tx.Logger().Warn("cannot read the settings for the timezone, using UTC",
|
||||
"owner", owner, "dayKey", dayKey, "error", err)
|
||||
return time.UTC
|
||||
}
|
||||
loc, err := time.LoadLocation(set.GetString("timezone"))
|
||||
if set == nil {
|
||||
return time.UTC
|
||||
}
|
||||
timezone := set.GetString("timezone")
|
||||
loc, err := time.LoadLocation(timezone)
|
||||
if err != nil {
|
||||
tx.Logger().Warn("unknown timezone in the settings, using UTC",
|
||||
"owner", owner, "dayKey", dayKey, "timezone", timezone, "error", err)
|
||||
return time.UTC
|
||||
}
|
||||
return loc
|
||||
|
||||
Reference in New Issue
Block a user