Skip to content

Commit

Permalink
Return the correct status code when request with invalid predicate is…
Browse files Browse the repository at this point in the history
… received

When request with invalid predicate is received the api returns 503
instead of 400 due to the fact that the UnsupportedPredicateErr is
wrapped.
  • Loading branch information
ivanruski committed Mar 31, 2021
1 parent ae910ac commit 670a13f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions http_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
Expand All @@ -14,7 +15,6 @@ import (
transactionidutils "github.com/Financial-Times/transactionid-utils-go"

"github.com/gorilla/mux"
"github.com/pkg/errors"
)

const (
Expand Down Expand Up @@ -187,7 +187,7 @@ func (hh *httpHandler) PutAnnotations(w http.ResponseWriter, r *http.Request) {

tid := transactionidutils.GetTransactionIDFromRequest(r)
err = hh.annotationsService.Write(uuid, lifecycle, platformVersion, tid, anns)
if err == annotations.UnsupportedPredicateErr {
if errors.Is(err, annotations.UnsupportedPredicateErr) {
hh.log.WithUUID(uuid).WithTransactionID(tid).WithError(err).Error("invalid predicate provided")
writeJSONError(w, "Please provide a valid predicate", http.StatusBadRequest)
return
Expand Down

0 comments on commit 670a13f

Please sign in to comment.