Return every error as {"error": "..."}
Echo errors, middleware and handlers used three different formats (message object, error object, bare string). One error handler now writes all of them the same way; status codes are unchanged.
This commit is contained in:
1 parent
bc7d406e41
commit
0ec2425f78
9 files changed
+67
-21
No files matched your search
@@ -34,7 +34,7 @@ func NewMusicHandler(music *backend.MusicService) *MusicHandler {
|
||||
func (m *MusicHandler) GetSong(ctx *echo.Context) error {
|
||||
song, err := strconv.Atoi(ctx.QueryParam("song"))
|
||||
if err != nil {
|
||||
return ctx.String(http.StatusBadRequest, "song must be a number")
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "song must be a number")
|
||||
}
|
||||
path, err := m.music.Song(song)
|
||||
return serveSong(ctx, path, err)
|
||||
@@ -204,7 +204,7 @@ func (m *MusicHandler) GetAllSoundtracksRandom(ctx *echo.Context) error {
|
||||
func (m *MusicHandler) PutPlayed(ctx *echo.Context) error {
|
||||
song, err := strconv.Atoi(ctx.QueryParam("song"))
|
||||
if err != nil {
|
||||
return ctx.JSON(http.StatusBadRequest, err.Error())
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "song must be a number")
|
||||
}
|
||||
logging.GetLogger().Info("Marking song as played", zap.Int("song_id", song))
|
||||
if err := m.music.SetPlayed(ctx.Request().Context(), song); err != nil {
|
||||
|
||||
Reference in new issue
Block a user