Skip to content

Commit

Permalink
fix: error messages in OpenAPI/Swagger / improve error messages from …
Browse files Browse the repository at this point in the history
…failed webhooks and client timeouts (#3218)
  • Loading branch information
alnr committed Apr 14, 2023
1 parent c15de85 commit b1bdcd3
Show file tree
Hide file tree
Showing 39 changed files with 488 additions and 3,390 deletions.
94 changes: 0 additions & 94 deletions .schema/openapi/patches/health.yaml

This file was deleted.

3 changes: 2 additions & 1 deletion continuity/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/pkg/errors"

"github.com/ory/herodot"
"github.com/ory/x/pointerx"
"github.com/ory/x/sqlxx"

"github.com/ory/kratos/x"
Expand Down Expand Up @@ -61,7 +62,7 @@ func (c *Container) Valid(identity uuid.UUID) error {
return errors.WithStack(herodot.ErrBadRequest.WithReasonf("You must restart the flow because the resumable session has expired."))
}

if identity != uuid.Nil && x.DerefUUID(c.IdentityID) != identity {
if identity != uuid.Nil && pointerx.Deref(c.IdentityID) != identity {
return errors.WithStack(herodot.ErrBadRequest.WithReasonf("You must restart the flow because the resumable session was initiated by another person."))
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
"{\"error\":{\"code\":404,\"status\":\"Not Found\",\"message\":\"Unable to locate the resource\"}}\n"
{
"error": {
"code": 404,
"status": "Not Found",
"message": "Unable to locate the resource"
}
}

Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
"{\"error\":{\"code\":404,\"status\":\"Not Found\",\"message\":\"Unable to locate the resource\"}}\n"
{
"error": {
"code": 404,
"status": "Not Found",
"message": "Unable to locate the resource"
}
}

Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
"{\"error\":{\"code\":400,\"status\":\"Bad Request\",\"debug\":\"could not parse parameter {id} as UUID, got \",\"message\":\"uuid: incorrect UUID length 10 in string \\\"not-a-uuid\\\"\"}}\n"
{
"error": {
"code": 400,
"status": "Bad Request",
"message": "uuid: incorrect UUID length 10 in string \"not-a-uuid\""
}
}

Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
"{\"error\":{\"code\":400,\"status\":\"Bad Request\",\"debug\":\"could not parse parameter {id} as UUID, got \",\"message\":\"uuid: incorrect UUID length 10 in string \\\"not-a-uuid\\\"\"}}\n"
{
"error": {
"code": 400,
"status": "Bad Request",
"message": "uuid: incorrect UUID length 10 in string \"not-a-uuid\""
}
}

13 changes: 6 additions & 7 deletions courier/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestHandler(t *testing.T) {
require.NoError(t, err)
require.NoError(t, res.Body.Close())

assert.EqualValues(t, expectCode, res.StatusCode, "%s", body)
assert.EqualValuesf(t, expectCode, res.StatusCode, "%s", body)
return gjson.ParseBytes(body)
}

Expand All @@ -80,7 +80,7 @@ func TestHandler(t *testing.T) {
}

parsed := get(t, ts, href, http.StatusOK)
require.True(t, parsed.IsArray(), "%s", parsed.Raw)
require.Truef(t, parsed.IsArray(), "%s", parsed.Raw)
return parsed
}

Expand Down Expand Up @@ -188,7 +188,7 @@ func TestHandler(t *testing.T) {
for _, tc := range tss {
t.Run("endpoint="+tc.name, func(t *testing.T) {
parsed := getList(t, tc.name, "")
require.Len(t, parsed.Array(), msgCount, "%s", parsed.Raw)
require.Lenf(t, parsed.Array(), msgCount, "%s", parsed.Raw)

for _, item := range parsed.Array() {
assert.Equal(t, "<redacted-unless-dev-mode>", item.Get("body").String())
Expand All @@ -201,7 +201,7 @@ func TestHandler(t *testing.T) {
for _, tc := range tss {
t.Run("endpoint="+tc.name, func(t *testing.T) {
parsed := getList(t, tc.name, "")
require.Len(t, parsed.Array(), msgCount, "%s", parsed.Raw)
require.Lenf(t, parsed.Array(), msgCount, "%s", parsed.Raw)

for _, item := range parsed.Array() {
assert.Equal(t, "body content", item.Get("body").String())
Expand Down Expand Up @@ -266,16 +266,15 @@ func TestHandler(t *testing.T) {
t.Run("endpoint="+tc.name, func(t *testing.T) {
body := getCourierMessag(tc.s, "not-a-uuid")

snapshotx.SnapshotT(t, body.String())
snapshotx.SnapshotTJSONString(t, body.String())
})
}
})
t.Run("case=returns an error if no message is found", func(t *testing.T) {
for _, tc := range tss {
t.Run("endpoint="+tc.name, func(t *testing.T) {
body := getCourierMessag(tc.s, uuid.Nil.String())

snapshotx.SnapshotT(t, body.String())
snapshotx.SnapshotTJSONString(t, body.String())
})
}
})
Expand Down
28 changes: 14 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,20 @@ require (
github.com/ory/dockertest/v3 v3.9.1
github.com/ory/go-acc v0.2.9-0.20230103102148-6b1c9a70dbbe
github.com/ory/graceful v0.1.4-0.20230301144740-e222150c51d0
github.com/ory/herodot v0.9.13
github.com/ory/herodot v0.10.2
github.com/ory/hydra-client-go/v2 v2.0.3
github.com/ory/jsonschema/v3 v3.0.8
github.com/ory/mail/v3 v3.0.0
github.com/ory/nosurf v1.2.7
github.com/ory/x v0.0.549
github.com/ory/x v0.0.551
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2
github.com/pkg/errors v0.9.1
github.com/pquerna/otp v1.4.0
github.com/rs/cors v1.8.2
github.com/samber/lo v1.37.0
github.com/sirupsen/logrus v1.9.0
github.com/slack-go/slack v0.7.4
github.com/spf13/cobra v1.6.1
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
github.com/sqs/goreturns v0.0.0-20181028201513-538ac6014518
github.com/stretchr/testify v1.8.2
Expand All @@ -96,13 +96,14 @@ require (
go.opentelemetry.io/otel/trace v1.11.1
golang.org/x/crypto v0.5.0
golang.org/x/net v0.8.0
golang.org/x/oauth2 v0.4.0
golang.org/x/oauth2 v0.6.0
golang.org/x/sync v0.1.0
golang.org/x/tools/cmd/cover v0.1.0-deprecated
google.golang.org/grpc v1.54.0
)

require (
cloud.google.com/go/compute v1.14.0 // indirect
cloud.google.com/go/compute v1.19.0 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
Expand All @@ -122,11 +123,11 @@ require (
github.com/bmatcuk/doublestar v1.3.4 // indirect
github.com/boombuler/barcode v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.2.0 // indirect
github.com/census-instrumentation/opencensus-proto v0.3.0 // indirect
github.com/census-instrumentation/opencensus-proto v0.4.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cloudflare/cfssl v1.6.1 // indirect
github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4 // indirect
github.com/cncf/xds/go v0.0.0-20211130200136-a8f946100490 // indirect
github.com/cncf/udpa/go v0.0.0-20220112060539-c52dc94e7fbe // indirect
github.com/cncf/xds/go v0.0.0-20230105202645-06c439db220b // indirect
github.com/cockroachdb/cockroach-go/v2 v2.2.16 // indirect
github.com/containerd/continuity v0.3.0 // indirect
github.com/coreos/go-semver v0.3.0 // indirect
Expand All @@ -141,8 +142,8 @@ require (
github.com/docker/go-units v0.5.0 // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/elliotchance/orderedmap v1.4.0 // indirect
github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1 // indirect
github.com/envoyproxy/protoc-gen-validate v0.6.2 // indirect
github.com/envoyproxy/go-control-plane v0.10.3 // indirect
github.com/envoyproxy/protoc-gen-validate v0.9.1 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/fatih/structs v1.1.0 // indirect
github.com/felixge/fgprof v0.9.3 // indirect
Expand Down Expand Up @@ -311,16 +312,15 @@ require (
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.21.0 // indirect
golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 // indirect
golang.org/x/mod v0.9.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/sys v0.7.0 // indirect
golang.org/x/term v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
golang.org/x/time v0.1.0 // indirect
golang.org/x/tools v0.7.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20221227171554-f9683d7f8bef // indirect
google.golang.org/grpc v1.52.0 // indirect
google.golang.org/genproto v0.0.0-20230403163135-c38d8f061ccd // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/alecthomas/kingpin.v2 v2.2.6 // indirect
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
Expand Down
Loading

0 comments on commit b1bdcd3

Please sign in to comment.