Skip to content

Commit

Permalink
Merge pull request #45 from form3tech-oss/nl-return-interaction-not-f…
Browse files Browse the repository at this point in the history
…ound

feat: Add interaction not found error
  • Loading branch information
nicholas-lebrun-form3 authored Oct 6, 2023
2 parents 4b791c4 + 6f60945 commit 7388a82
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion internal/app/pactproxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func (a *api) interactionsGetHandler(c echo.Context) error {
alias := c.Param("alias")
interaction, found := a.interactions.Load(alias)
if !found {
return c.JSON(http.StatusBadRequest, httpresponse.Errorf("interaction %q not found", alias))
return c.JSON(http.StatusNotFound, httpresponse.Errorf("interaction %q not found", alias))
}

return c.JSON(http.StatusOK, interaction)
Expand Down
2 changes: 1 addition & 1 deletion internal/app/pactproxy/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func TestInteractionsGetHandler(t *testing.T) {
{
name: "interaction not found",
interactions: &Interactions{},
code: http.StatusBadRequest,
code: http.StatusNotFound,
body: `{"error_message":"interaction \"test\" not found"}`,
},
} {
Expand Down
5 changes: 5 additions & 0 deletions pkg/pactproxy/pactproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
log "github.com/sirupsen/logrus"
)

var InteractionNotFoundError = errors.New("interaction not found")

type PactProxy struct {
client http.Client
url string
Expand Down Expand Up @@ -144,6 +146,9 @@ func (p *PactProxy) ReadInteractionDetails(alias string) (*Interaction, error) {
return nil, errors.Wrap(err, "http get")
}
if res.StatusCode != http.StatusOK {
if res.StatusCode == http.StatusNotFound {
return nil, InteractionNotFoundError
}
return nil, errors.New("fail")
}
interaction := &Interaction{}
Expand Down

0 comments on commit 7388a82

Please sign in to comment.