You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
writer.WriteJson(...) returns an error. The JSON serialization can fail for many reasons (eg: NaN, channel, complex, ...).
If such error is a valid possibility in the program, if the JSON API deals with data that can contain sources of serialization failures, then, the regular error handling is appropriate:
err := w.WriteJson(...)
if err != nil {
// the following, or any other appropriate error handling
rest.Error(w, err.Error(), http.StatusInternalServerError)
return
}
But if a serialization error is considered a program bug, worth a stop in the processing of the request, then it could be a valid use of panic:
err := w.WriteJson(...)
if err != nil {
panic(err.Error())
}
This last piece of code could be provided by the framework like this: func MustWriteJson(w ResponseWriter, v interface{})
The text was updated successfully, but these errors were encountered:
writer.WriteJson(...)
returns an error. The JSON serialization can fail for many reasons (eg: NaN, channel, complex, ...).If such error is a valid possibility in the program, if the JSON API deals with data that can contain sources of serialization failures, then, the regular error handling is appropriate:
But if a serialization error is considered a program bug, worth a stop in the processing of the request, then it could be a valid use of
panic
:This last piece of code could be provided by the framework like this:
func MustWriteJson(w ResponseWriter, v interface{})
The text was updated successfully, but these errors were encountered: