Skip to content

Commit

Permalink
refactor: add debug prints for error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksandrMatsko committed Sep 18, 2024
1 parent dfba55e commit d6cd538
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions api/handler/triggers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package handler
import (
"encoding/json"
"fmt"
"log"
"net/http"
"net/url"
"strconv"
Expand Down Expand Up @@ -155,6 +156,9 @@ func createTrigger(writer http.ResponseWriter, request *http.Request) {
func getTriggerFromRequest(request *http.Request) (*dto.Trigger, *api.ErrorResponse) {
trigger := &dto.Trigger{}
if err := render.Bind(request, trigger); err != nil {

log.Printf("err type: %T, msg: %s", err, err)

switch typedErr := err.(type) { // nolint:errorlint
case local.ErrParseExpr, local.ErrEvalExpr, local.ErrUnknownFunction:
return nil, api.ErrorInvalidRequest(fmt.Errorf("invalid graphite targets: %s", err.Error()))
Expand All @@ -172,6 +176,9 @@ func getTriggerFromRequest(request *http.Request) (*dto.Trigger, *api.ErrorRespo
case *json.UnmarshalTypeError:
return nil, api.ErrorInvalidRequest(fmt.Errorf("invalid payload: %s", err.Error()))
case *prometheus.Error:

log.Printf("prom err: type: %s, msg: %s, detail: %s", typedErr.Type, typedErr.Msg, typedErr.Detail)

switch typedErr.Type {
case prometheus.ErrBadData:
return nil, api.ErrorInvalidRequest(fmt.Errorf("invalid prometheus targets: %w", err))
Expand Down

0 comments on commit d6cd538

Please sign in to comment.