Skip to content

Commit

Permalink
fix(http): improve error handling and response to api consumer for or…
Browse files Browse the repository at this point in the history
…g service
  • Loading branch information
jsteenb2 committed Feb 4, 2020
1 parent 5f34f61 commit 26b9167
Show file tree
Hide file tree
Showing 15 changed files with 200 additions and 422 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
1. [16656](https://github.com/influxdata/influxdb/pull/16656): Check engine closed before collecting index metrics
1. [16412](https://github.com/influxdata/influxdb/pull/16412): Reject writes which use any of the reserved tag keys
1. [16715](https://github.com/influxdata/influxdb/pull/16715): Fixed dashboard mapping for getDashboards to map correct prop
1. [16716](https://github.com/influxdata/influxdb/pull/16716): Improve the lacking error responses for unmarshal errors in org service

### Bug Fixes

Expand Down
4 changes: 2 additions & 2 deletions http/bucket_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ func decodeGetBucketLogRequest(ctx context.Context, r *http.Request) (*getBucket
return nil, err
}

opts, err := decodeFindOptions(ctx, r)
opts, err := decodeFindOptions(r)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -602,7 +602,7 @@ func decodeGetBucketsRequest(ctx context.Context, r *http.Request) (*getBucketsR
qp := r.URL.Query()
req := &getBucketsRequest{}

opts, err := decodeFindOptions(ctx, r)
opts, err := decodeFindOptions(r)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion http/check_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ func decodeCheckFilter(ctx context.Context, r *http.Request) (*influxdb.CheckFil
},
}

opts, err := decodeFindOptions(ctx, r)
opts, err := decodeFindOptions(r)
if err != nil {
return f, nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions http/dashboard_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ func decodeGetDashboardsRequest(ctx context.Context, r *http.Request) (*getDashb
qp := r.URL.Query()
req := &getDashboardsRequest{}

opts, err := decodeFindOptions(ctx, r)
opts, err := decodeFindOptions(r)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -591,7 +591,7 @@ func decodeGetDashboardLogRequest(ctx context.Context, r *http.Request) (*getDas
return nil, err
}

opts, err := decodeFindOptions(ctx, r)
opts, err := decodeFindOptions(r)
if err != nil {
return nil, err
}
Expand Down
47 changes: 47 additions & 0 deletions http/helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package http

import (
"context"
"net/url"

"github.com/influxdata/httprouter"
"github.com/influxdata/influxdb"
)

func decodeIDFromCtx(ctx context.Context, name string) (influxdb.ID, error) {
params := httprouter.ParamsFromContext(ctx)
idStr := params.ByName(name)

if idStr == "" {
return 0, &influxdb.Error{
Code: influxdb.EInvalid,
Msg: "url missing " + name,
}
}

var i influxdb.ID
if err := i.DecodeFromString(idStr); err != nil {
return 0, &influxdb.Error{
Code: influxdb.EInvalid,
Err: err,
}
}

return i, nil
}

func decodeIDFromQuery(v url.Values, key string) (influxdb.ID, error) {
idStr := v.Get(key)
if idStr == "" {
return 0, nil
}

id, err := influxdb.IDFromString(idStr)
if err != nil {
return 0, &influxdb.Error{
Code: influxdb.EInvalid,
Err: err,
}
}
return *id, nil
}
2 changes: 1 addition & 1 deletion http/notification_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func decodeNotificationEndpointFilter(ctx context.Context, r *http.Request) (inf
},
}

opts, err := decodeFindOptions(ctx, r)
opts, err := decodeFindOptions(r)
if err != nil {
return influxdb.NotificationEndpointFilter{}, influxdb.FindOptions{}, err
}
Expand Down
2 changes: 1 addition & 1 deletion http/notification_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ func decodeNotificationRuleFilter(ctx context.Context, r *http.Request) (*influx
f.UserResourceMappingFilter = *urm
}

opts, err := decodeFindOptions(ctx, r)
opts, err := decodeFindOptions(r)
if err != nil {
return f, nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions http/onboarding.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (h *SetupHandler) handlePostSetup(w http.ResponseWriter, r *http.Request) {
type onboardingResponse struct {
User *UserResponse `json:"user"`
Bucket *bucketResponse `json:"bucket"`
Organization *orgResponse `json:"org"`
Organization orgResponse `json:"org"`
Auth *authResponse `json:"auth"`
}

Expand All @@ -119,7 +119,7 @@ func newOnboardingResponse(results *platform.OnboardingResults) *onboardingRespo
return &onboardingResponse{
User: newUserResponse(results.User),
Bucket: newBucketResponse(results.Bucket, []*platform.Label{}),
Organization: newOrgResponse(results.Org),
Organization: newOrgResponse(*results.Org),
Auth: newAuthResponse(results.Auth, results.Org, results.User, ps),
}
}
Expand Down
Loading

0 comments on commit 26b9167

Please sign in to comment.