Add API Error Handler (#74)
* Add error handler that converts from rpc.Status errors to Watchtower API errors. * Better testing for ErrorHandler. * Rename testcase and remove empty default switch case. * Change the error status back to int64. * Converting everything to int32s. jsonpb wraps int64s as a string which we dont like. We'll figure out how to use values larger than int64s when it comes up. * Remove special casing for TraceId which isn't needed anymore. * Removing wrappers from error details since we never need to know when they are set or unset from the end user. * Using the helper error functions inside the project service. * Correct usage of hclog, replace panic with Error log. * Adding periods to all API returned errors, correct spelling, fix missed invalid argument error not using helper function. * Change our logged errors to Error instead of Warn. * Add TODO for defining and using our own defined API error codes. * Add TODO to remove internal error messages.
This commit is contained in:
1 parent
b718091419
commit
44152ae63e
12 files changed
+354
-130
No files matched your search
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/hashicorp/watchtower/api"
|
||||
"github.com/hashicorp/watchtower/globals"
|
||||
"github.com/hashicorp/watchtower/internal/gen/controller/api/services"
|
||||
"github.com/hashicorp/watchtower/internal/servers/controller/handlers"
|
||||
"github.com/hashicorp/watchtower/internal/servers/controller/handlers/host_catalogs"
|
||||
"github.com/hashicorp/watchtower/internal/servers/controller/handlers/host_sets"
|
||||
"github.com/hashicorp/watchtower/internal/servers/controller/handlers/hosts"
|
||||
@@ -57,7 +58,7 @@ func handleGrpcGateway(c *Controller) http.Handler {
|
||||
// Register*ServiceHandlerServer methods ignore the passed in ctx. Using the baseContext now just in case this changes
|
||||
// in the future, at which point we'll want to be using the baseContext.
|
||||
ctx := c.baseContext
|
||||
mux := runtime.NewServeMux()
|
||||
mux := runtime.NewServeMux(runtime.WithProtoErrorHandler(handlers.ErrorHandler(c.logger)))
|
||||
services.RegisterHostCatalogServiceHandlerServer(ctx, mux, &host_catalogs.Service{})
|
||||
services.RegisterHostSetServiceHandlerServer(ctx, mux, &host_sets.Service{})
|
||||
services.RegisterHostServiceHandlerServer(ctx, mux, &hosts.Service{})
|
||||
|
||||
Reference in new issue
Block a user