feat(http): improve error handling (#1006)

This commit is contained in:
ze0s 2023-07-02 14:03:39 +02:00 committed by GitHub
parent 5cdf68bc77
commit c361f23139
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 94 additions and 66 deletions

View file

@ -44,8 +44,11 @@ func (h indexerHandler) Routes(r chi.Router) {
r.Put("/", h.update)
r.Get("/", h.getAll)
r.Get("/options", h.list)
r.Delete("/{indexerID}", h.delete)
r.Post("/{id}/api/test", h.testApi)
r.Route("/{indexerID}", func(r chi.Router) {
r.Delete("/", h.delete)
r.Post("/api/test", h.testApi)
})
}
func (h indexerHandler) getSchema(w http.ResponseWriter, r *http.Request) {
@ -104,7 +107,11 @@ func (h indexerHandler) delete(w http.ResponseWriter, r *http.Request) {
idParam = chi.URLParam(r, "indexerID")
)
id, _ := strconv.Atoi(idParam)
id, err := strconv.Atoi(idParam)
if err != nil {
h.encoder.Error(w, err)
return
}
if err := h.service.Delete(ctx, id); err != nil {
h.encoder.Error(w, err)
@ -139,7 +146,7 @@ func (h indexerHandler) list(w http.ResponseWriter, r *http.Request) {
func (h indexerHandler) testApi(w http.ResponseWriter, r *http.Request) {
var (
ctx = r.Context()
idParam = chi.URLParam(r, "id")
idParam = chi.URLParam(r, "indexerID")
req domain.IndexerTestApiRequest
)