From 8945d406fedb5c9ab14708b15bf1578ad3e3304f Mon Sep 17 00:00:00 2001 From: Maciej Winnicki Date: Mon, 12 Feb 2018 09:40:22 +0100 Subject: [PATCH] move errors to respective packages --- function/errors.go | 43 ++++++++++++++++--- httpapi/httpapi.go | 23 +++++----- libkv/function.go | 22 +++++----- libkv/function_test.go | 22 +++++----- libkv/functions_errors.go | 34 --------------- libkv/subscription.go | 14 +++--- libkv/subscription_test.go | 14 +++--- .../errors.go | 41 +++++++----------- 8 files changed, 98 insertions(+), 115 deletions(-) delete mode 100644 libkv/functions_errors.go rename libkv/subscriptions_errors.go => subscription/errors.go (64%) diff --git a/function/errors.go b/function/errors.go index a944259..8d7e501 100644 --- a/function/errors.go +++ b/function/errors.go @@ -1,30 +1,59 @@ package function -import "fmt" +import ( + "fmt" +) + +// ErrFunctionNotFound occurs when function couldn't been found in the discovery. +type ErrFunctionNotFound struct { + ID ID +} + +func (e ErrFunctionNotFound) Error() string { + return fmt.Sprintf("Function %q not found.", string(e.ID)) +} + +// ErrFunctionAlreadyRegistered occurs when function with specified name is already registered. +type ErrFunctionAlreadyRegistered struct { + ID ID +} + +func (e ErrFunctionAlreadyRegistered) Error() string { + return fmt.Sprintf("Function %q already registered.", string(e.ID)) +} + +// ErrFunctionValidation occurs when function payload doesn't validate. +type ErrFunctionValidation struct { + Message string +} + +func (e ErrFunctionValidation) Error() string { + return fmt.Sprintf("Function doesn't validate. Validation error: %q", e.Message) +} // ErrFunctionCallFailed occurs when function call failed because of provider error. type ErrFunctionCallFailed struct { - original error + Original error } func (e ErrFunctionCallFailed) Error() string { - return fmt.Sprintf("Function call failed. Error: %q", e.original) + return fmt.Sprintf("Function call failed. Error: %q", e.Original) } // ErrFunctionProviderError occurs when function call failed because of provider error. type ErrFunctionProviderError struct { - original error + Original error } func (e ErrFunctionProviderError) Error() string { - return fmt.Sprintf("Function call failed because of provider error. Error: %q", e.original) + return fmt.Sprintf("Function call failed because of provider error. Error: %q", e.Original) } // ErrFunctionError occurs when function call failed because of function error. type ErrFunctionError struct { - original error + Original error } func (e ErrFunctionError) Error() string { - return fmt.Sprintf("Function call failed because of runtime error. Error: %q", e.original) + return fmt.Sprintf("Function call failed because of runtime error. Error: %q", e.Original) } diff --git a/httpapi/httpapi.go b/httpapi/httpapi.go index 4da722a..fcda552 100644 --- a/httpapi/httpapi.go +++ b/httpapi/httpapi.go @@ -8,7 +8,6 @@ import ( "github.com/julienschmidt/httprouter" "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/serverless/event-gateway/function" - "github.com/serverless/event-gateway/libkv" "github.com/serverless/event-gateway/subscription" ) @@ -40,7 +39,7 @@ func (h HTTPAPI) getFunction(w http.ResponseWriter, r *http.Request, params http fn, err := h.Functions.GetFunction(function.ID(params.ByName("id"))) if err != nil { - if _, ok := err.(*libkv.ErrNotFound); ok { + if _, ok := err.(*function.ErrFunctionNotFound); ok { w.WriteHeader(http.StatusNotFound) } else { w.WriteHeader(http.StatusInternalServerError) @@ -84,9 +83,9 @@ func (h HTTPAPI) registerFunction(w http.ResponseWriter, r *http.Request, params output, err := h.Functions.RegisterFunction(fn) if err != nil { - if _, ok := err.(*libkv.ErrValidation); ok { + if _, ok := err.(*function.ErrFunctionValidation); ok { w.WriteHeader(http.StatusBadRequest) - } else if _, ok := err.(*libkv.ErrAlreadyRegistered); ok { + } else if _, ok := err.(*function.ErrFunctionAlreadyRegistered); ok { w.WriteHeader(http.StatusBadRequest) } else { w.WriteHeader(http.StatusInternalServerError) @@ -115,9 +114,9 @@ func (h HTTPAPI) updateFunction(w http.ResponseWriter, r *http.Request, params h fn.ID = function.ID(params.ByName("id")) output, err := h.Functions.UpdateFunction(fn) if err != nil { - if _, ok := err.(*libkv.ErrValidation); ok { + if _, ok := err.(*function.ErrFunctionValidation); ok { w.WriteHeader(http.StatusBadRequest) - } else if _, ok := err.(*libkv.ErrNotFound); ok { + } else if _, ok := err.(*function.ErrFunctionNotFound); ok { w.WriteHeader(http.StatusNotFound) } else { w.WriteHeader(http.StatusInternalServerError) @@ -136,7 +135,7 @@ func (h HTTPAPI) deleteFunction(w http.ResponseWriter, r *http.Request, params h err := h.Functions.DeleteFunction(function.ID(params.ByName("id"))) if err != nil { - if _, ok := err.(*libkv.ErrNotFound); ok { + if _, ok := err.(*function.ErrFunctionNotFound); ok { w.WriteHeader(http.StatusNotFound) } else { w.WriteHeader(http.StatusInternalServerError) @@ -163,13 +162,13 @@ func (h HTTPAPI) createSubscription(w http.ResponseWriter, r *http.Request, para output, err := h.Subscriptions.CreateSubscription(s) if err != nil { - if _, ok := err.(*libkv.ErrSubscriptionAlreadyExists); ok { + if _, ok := err.(*subscription.ErrSubscriptionAlreadyExists); ok { w.WriteHeader(http.StatusBadRequest) - } else if _, ok := err.(*libkv.ErrFunctionNotFound); ok { + } else if _, ok := err.(*function.ErrFunctionNotFound); ok { w.WriteHeader(http.StatusBadRequest) - } else if _, ok := err.(*libkv.ErrSubscriptionValidation); ok { + } else if _, ok := err.(*subscription.ErrSubscriptionValidation); ok { w.WriteHeader(http.StatusBadRequest) - } else if _, ok := err.(*libkv.ErrPathConfict); ok { + } else if _, ok := err.(*subscription.ErrPathConfict); ok { w.WriteHeader(http.StatusBadRequest) } else { w.WriteHeader(http.StatusInternalServerError) @@ -192,7 +191,7 @@ func (h HTTPAPI) deleteSubscription(w http.ResponseWriter, r *http.Request, para err := h.Subscriptions.DeleteSubscription(subscription.ID(sid)) if err != nil { - if _, ok := err.(*libkv.ErrSubscriptionNotFound); ok { + if _, ok := err.(*subscription.ErrSubscriptionNotFound); ok { w.WriteHeader(http.StatusNotFound) } else { w.WriteHeader(http.StatusInternalServerError) diff --git a/libkv/function.go b/libkv/function.go index 981b157..12673fc 100644 --- a/libkv/function.go +++ b/libkv/function.go @@ -21,7 +21,7 @@ func (f Service) RegisterFunction(fn *function.Function) (*function.Function, er _, err := f.FunctionStore.Get(string(fn.ID), &store.ReadOptions{Consistent: true}) if err == nil { - return nil, &ErrAlreadyRegistered{fn.ID} + return nil, &function.ErrFunctionAlreadyRegistered{fn.ID} } byt, err := json.Marshal(fn) @@ -43,7 +43,7 @@ func (f Service) RegisterFunction(fn *function.Function) (*function.Function, er func (f Service) UpdateFunction(fn *function.Function) (*function.Function, error) { _, err := f.FunctionStore.Get(string(fn.ID), &store.ReadOptions{Consistent: true}) if err != nil { - return nil, &ErrNotFound{fn.ID} + return nil, &function.ErrFunctionNotFound{fn.ID} } if err = f.validateFunction(fn); err != nil { @@ -69,7 +69,7 @@ func (f Service) UpdateFunction(fn *function.Function) (*function.Function, erro func (f Service) GetFunction(id function.ID) (*function.Function, error) { kv, err := f.FunctionStore.Get(string(id), &store.ReadOptions{Consistent: true}) if err != nil { - return nil, &ErrNotFound{id} + return nil, &function.ErrFunctionNotFound{id} } fn := function.Function{} @@ -108,7 +108,7 @@ func (f Service) GetAllFunctions() ([]*function.Function, error) { func (f Service) DeleteFunction(id function.ID) error { err := f.FunctionStore.Delete(string(id)) if err != nil { - return &ErrNotFound{id} + return &function.ErrFunctionNotFound{id} } f.Log.Debug("Function deleted.", zap.String("functionId", string(id))) @@ -121,12 +121,12 @@ func (f Service) validateFunction(fn *function.Function) error { validate.RegisterValidation("functionid", functionIDValidator) err := validate.Struct(fn) if err != nil { - return &ErrValidation{err.Error()} + return &function.ErrFunctionValidation{err.Error()} } if fn.Provider.Type == function.AWSLambda { if fn.Provider.ARN == "" || fn.Provider.Region == "" { - return &ErrValidation{"Missing required fields for AWS Lambda function."} + return &function.ErrFunctionValidation{"Missing required fields for AWS Lambda function."} } } @@ -135,7 +135,7 @@ func (f Service) validateFunction(fn *function.Function) error { } if fn.Provider.Type == function.HTTPEndpoint && fn.Provider.URL == "" { - return &ErrValidation{"Missing required fields for HTTP endpoint."} + return &function.ErrFunctionValidation{"Missing required fields for HTTP endpoint."} } if fn.Provider.Type == function.Weighted { @@ -147,16 +147,16 @@ func (f Service) validateFunction(fn *function.Function) error { func (f Service) validateEmulator(fn *function.Function) error { if fn.Provider.EmulatorURL == "" { - return &ErrValidation{"Missing required field emulatorURL for Emulator function."} + return &function.ErrFunctionValidation{"Missing required field emulatorURL for Emulator function."} } else if fn.Provider.APIVersion == "" { - return &ErrValidation{"Missing required field apiVersion for Emulator function."} + return &function.ErrFunctionValidation{"Missing required field apiVersion for Emulator function."} } return nil } func (f Service) validateWeighted(fn *function.Function) error { if len(fn.Provider.Weighted) == 0 { - return &ErrValidation{"Missing required fields for weighted function."} + return &function.ErrFunctionValidation{"Missing required fields for weighted function."} } weightTotal := uint(0) @@ -165,7 +165,7 @@ func (f Service) validateWeighted(fn *function.Function) error { } if weightTotal < 1 { - return &ErrValidation{"Function weights sum to zero."} + return &function.ErrFunctionValidation{"Function weights sum to zero."} } return nil diff --git a/libkv/function_test.go b/libkv/function_test.go index 1551ab6..c2e4793 100644 --- a/libkv/function_test.go +++ b/libkv/function_test.go @@ -35,7 +35,7 @@ func TestRegisterFunction_ValidationError(t *testing.T) { _, err := service.RegisterFunction(&function.Function{ID: "testid", Provider: &function.Provider{Type: function.HTTPEndpoint}}) - assert.Equal(t, err, &ErrValidation{"Missing required fields for HTTP endpoint."}) + assert.Equal(t, err, &function.ErrFunctionValidation{"Missing required fields for HTTP endpoint."}) } func TestRegisterFunction_AlreadyExistsError(t *testing.T) { @@ -48,7 +48,7 @@ func TestRegisterFunction_AlreadyExistsError(t *testing.T) { _, err := service.RegisterFunction(&function.Function{ID: "testid", Provider: &function.Provider{Type: function.HTTPEndpoint, URL: "http://example.com"}}) - assert.Equal(t, err, &ErrAlreadyRegistered{ID: "testid"}) + assert.Equal(t, err, &function.ErrFunctionAlreadyRegistered{ID: "testid"}) } func TestRegisterFunction_PutError(t *testing.T) { @@ -89,7 +89,7 @@ func TestUpdateFunction_ValidationError(t *testing.T) { _, err := service.UpdateFunction(&function.Function{ID: "testid", Provider: &function.Provider{Type: function.HTTPEndpoint}}) - assert.Equal(t, err, &ErrValidation{"Missing required fields for HTTP endpoint."}) + assert.Equal(t, err, &function.ErrFunctionValidation{"Missing required fields for HTTP endpoint."}) } func TestUpdateFunction_NotFoundError(t *testing.T) { @@ -102,7 +102,7 @@ func TestUpdateFunction_NotFoundError(t *testing.T) { _, err := service.UpdateFunction(&function.Function{ID: "testid", Provider: &function.Provider{Type: function.HTTPEndpoint, URL: "http://example.com"}}) - assert.Equal(t, err, &ErrNotFound{ID: "testid"}) + assert.Equal(t, err, &function.ErrFunctionNotFound{ID: "testid"}) } func TestUpdateFunction_PutError(t *testing.T) { @@ -142,7 +142,7 @@ func TestGetFunction_NotFound(t *testing.T) { _, err := service.GetFunction(function.ID("testid")) - assert.Equal(t, err, &ErrNotFound{"testid"}) + assert.Equal(t, err, &function.ErrFunctionNotFound{"testid"}) } func TestGetAllFunctions(t *testing.T) { @@ -206,7 +206,7 @@ func TestValidateFunction_AWSLambdaMissingRegion(t *testing.T) { err := service.validateFunction(&function.Function{ID: "id", Provider: &function.Provider{Type: function.AWSLambda, ARN: "arn::"}}) - assert.Equal(t, err, &ErrValidation{"Missing required fields for AWS Lambda function."}) + assert.Equal(t, err, &function.ErrFunctionValidation{"Missing required fields for AWS Lambda function."}) } func TestValidateFunction_AWSLambdaMissingARN(t *testing.T) { @@ -214,7 +214,7 @@ func TestValidateFunction_AWSLambdaMissingARN(t *testing.T) { err := service.validateFunction(&function.Function{ID: "id", Provider: &function.Provider{Type: function.AWSLambda, Region: "us-east-1"}}) - assert.Equal(t, err, &ErrValidation{"Missing required fields for AWS Lambda function."}) + assert.Equal(t, err, &function.ErrFunctionValidation{"Missing required fields for AWS Lambda function."}) } func TestValidateFunction_HTTPMissingURL(t *testing.T) { @@ -222,7 +222,7 @@ func TestValidateFunction_HTTPMissingURL(t *testing.T) { err := service.validateFunction(&function.Function{ID: "id", Provider: &function.Provider{Type: function.HTTPEndpoint}}) - assert.Equal(t, err, &ErrValidation{"Missing required fields for HTTP endpoint."}) + assert.Equal(t, err, &function.ErrFunctionValidation{"Missing required fields for HTTP endpoint."}) } func TestValidateFunction_MissingID(t *testing.T) { @@ -230,7 +230,7 @@ func TestValidateFunction_MissingID(t *testing.T) { err := service.validateFunction(&function.Function{Provider: &function.Provider{Type: function.HTTPEndpoint}}) - assert.Equal(t, err, &ErrValidation{"Key: 'Function.ID' Error:Field validation for 'ID' failed on the 'required' tag"}) + assert.Equal(t, err, &function.ErrFunctionValidation{"Key: 'Function.ID' Error:Field validation for 'ID' failed on the 'required' tag"}) } func TestValidateFunction_EmulatorMissingURL(t *testing.T) { @@ -238,7 +238,7 @@ func TestValidateFunction_EmulatorMissingURL(t *testing.T) { err := service.validateFunction(&function.Function{ID: "id", Provider: &function.Provider{Type: function.Emulator}}) - assert.Equal(t, err, &ErrValidation{"Missing required field emulatorURL for Emulator function."}) + assert.Equal(t, err, &function.ErrFunctionValidation{"Missing required field emulatorURL for Emulator function."}) } func TestValidateFunction_EmulatorMissingAPIVersion(t *testing.T) { @@ -246,5 +246,5 @@ func TestValidateFunction_EmulatorMissingAPIVersion(t *testing.T) { err := service.validateFunction(&function.Function{ID: "id", Provider: &function.Provider{Type: function.Emulator, EmulatorURL: "http://example.com"}}) - assert.Equal(t, err, &ErrValidation{"Missing required field apiVersion for Emulator function."}) + assert.Equal(t, err, &function.ErrFunctionValidation{"Missing required field apiVersion for Emulator function."}) } diff --git a/libkv/functions_errors.go b/libkv/functions_errors.go deleted file mode 100644 index 070ecb5..0000000 --- a/libkv/functions_errors.go +++ /dev/null @@ -1,34 +0,0 @@ -package libkv - -import ( - "fmt" - - "github.com/serverless/event-gateway/function" -) - -// ErrNotFound occurs when function couldn't been found in the discovery. -type ErrNotFound struct { - ID function.ID -} - -func (e ErrNotFound) Error() string { - return fmt.Sprintf("Function %q not found.", string(e.ID)) -} - -// ErrAlreadyRegistered occurs when function with specified name is already registered.. -type ErrAlreadyRegistered struct { - ID function.ID -} - -func (e ErrAlreadyRegistered) Error() string { - return fmt.Sprintf("Function %q already registered.", string(e.ID)) -} - -// ErrValidation occurs when function payload doesn't validate. -type ErrValidation struct { - message string -} - -func (e ErrValidation) Error() string { - return fmt.Sprintf("Function doesn't validate. Validation error: %q", e.message) -} diff --git a/libkv/subscription.go b/libkv/subscription.go index ba3a919..9abebbe 100644 --- a/libkv/subscription.go +++ b/libkv/subscription.go @@ -28,7 +28,7 @@ func (ps Service) CreateSubscription(s *subscription.Subscription) (*subscriptio s.ID = newSubscriptionID(s) _, err = ps.SubscriptionStore.Get(string(s.ID), &store.ReadOptions{Consistent: true}) if err == nil { - return nil, &ErrSubscriptionAlreadyExists{ + return nil, &subscription.ErrSubscriptionAlreadyExists{ ID: s.ID, } } @@ -45,7 +45,7 @@ func (ps Service) CreateSubscription(s *subscription.Subscription) (*subscriptio return nil, err } if !exists { - return nil, &ErrFunctionNotFound{string(s.FunctionID)} + return nil, &function.ErrFunctionNotFound{s.FunctionID} } buf, err := json.Marshal(s) @@ -71,7 +71,7 @@ func (ps Service) DeleteSubscription(id subscription.ID) error { err = ps.SubscriptionStore.Delete(string(sub.ID)) if err != nil { - return &ErrSubscriptionNotFound{sub.ID} + return &subscription.ErrSubscriptionNotFound{sub.ID} } if sub.Event == event.TypeHTTP { @@ -113,7 +113,7 @@ func (ps Service) GetAllSubscriptions() ([]*subscription.Subscription, error) { func (ps Service) getSubscription(id subscription.ID) (*subscription.Subscription, error) { rawsub, err := ps.SubscriptionStore.Get(string(id), &store.ReadOptions{Consistent: true}) if err != nil { - return nil, &ErrSubscriptionNotFound{id} + return nil, &subscription.ErrSubscriptionNotFound{id} } sub := &subscription.Subscription{} @@ -151,7 +151,7 @@ func (ps Service) createEndpoint(method, path string) error { err = tree.AddRoute(path, function.ID(""), nil) if err != nil { - return &ErrPathConfict{err.Error()} + return &subscription.ErrPathConfict{err.Error()} } buf, err := json.Marshal(e) @@ -200,11 +200,11 @@ func (ps Service) validateSubscription(s *subscription.Subscription) error { validate.RegisterValidation("eventtype", eventTypeValidator) err := validate.Struct(s) if err != nil { - return &ErrSubscriptionValidation{err.Error()} + return &subscription.ErrSubscriptionValidation{err.Error()} } if s.Event == event.TypeHTTP && s.Method == "" { - return &ErrSubscriptionValidation{"Missing required fields (method, path) for HTTP event."} + return &subscription.ErrSubscriptionValidation{"Missing required fields (method, path) for HTTP event."} } return nil diff --git a/libkv/subscription_test.go b/libkv/subscription_test.go index 625ed00..bf5328f 100644 --- a/libkv/subscription_test.go +++ b/libkv/subscription_test.go @@ -41,7 +41,7 @@ func TestCreateSubscription_HTTPValidationError(t *testing.T) { _, err := subs.CreateSubscription(&subscription.Subscription{ID: "testid", Event: "http", FunctionID: "func"}) - assert.Equal(t, err, &ErrSubscriptionValidation{original: "Missing required fields (method, path) for HTTP event."}) + assert.Equal(t, err, &subscription.ErrSubscriptionValidation{"Missing required fields (method, path) for HTTP event."}) } func TestCreateSubscription_OK(t *testing.T) { @@ -68,7 +68,7 @@ func TestCreateSubscription_ValidationError(t *testing.T) { _, err := subs.CreateSubscription(&subscription.Subscription{}) - assert.Equal(t, err, &ErrSubscriptionValidation{original: "Key: 'Subscription.Event' Error:Field validation for 'Event' failed on the 'required' tag\nKey: 'Subscription.FunctionID' Error:Field validation for 'FunctionID' failed on the 'required' tag"}) + assert.Equal(t, err, &subscription.ErrSubscriptionValidation{"Key: 'Subscription.Event' Error:Field validation for 'Event' failed on the 'required' tag\nKey: 'Subscription.FunctionID' Error:Field validation for 'FunctionID' failed on the 'required' tag"}) } func TestCreateSubscription_AlreadyExistsError(t *testing.T) { @@ -81,7 +81,7 @@ func TestCreateSubscription_AlreadyExistsError(t *testing.T) { _, err := subs.CreateSubscription(&subscription.Subscription{ID: "testid", Event: "test", FunctionID: "func"}) - assert.Equal(t, err, &ErrSubscriptionAlreadyExists{ID: "test,func,%2F"}) + assert.Equal(t, err, &subscription.ErrSubscriptionAlreadyExists{ID: "test,func,%2F"}) } func TestCreateSubscription_EndpointPathConflictError(t *testing.T) { @@ -97,7 +97,7 @@ func TestCreateSubscription_EndpointPathConflictError(t *testing.T) { _, err := subs.CreateSubscription(&subscription.Subscription{ID: "testid", Event: "http", FunctionID: "func", Method: "GET", Path: "/:id"}) - assert.Equal(t, err, &ErrPathConfict{`parameter with different name ("name") already defined: for route: /:id`}) + assert.Equal(t, err, &subscription.ErrPathConfict{`parameter with different name ("name") already defined: for route: /:id`}) } func TestCreateSubscription_EndpointPutError(t *testing.T) { @@ -164,7 +164,7 @@ func TestCreateSubscription_FunctionExistsError(t *testing.T) { _, err := subs.CreateSubscription(&subscription.Subscription{ID: "testid", Event: "http", FunctionID: "func", Method: "GET", Path: "/"}) - assert.Equal(t, err, &ErrFunctionNotFound{functionID: "func"}) + assert.Equal(t, err, &function.ErrFunctionNotFound{ID: "func"}) } func TestCreateSubscription_PutError(t *testing.T) { @@ -211,7 +211,7 @@ func TestDeleteSubscription_GetError(t *testing.T) { err := subs.DeleteSubscription(subscription.ID("testid")) - assert.Equal(t, err, &ErrSubscriptionNotFound{"testid"}) + assert.Equal(t, err, &subscription.ErrSubscriptionNotFound{"testid"}) } func TestDeleteSubscription_DeleteError(t *testing.T) { @@ -226,7 +226,7 @@ func TestDeleteSubscription_DeleteError(t *testing.T) { err := subs.DeleteSubscription(subscription.ID("testid")) - assert.Equal(t, err, &ErrSubscriptionNotFound{"testid"}) + assert.Equal(t, err, &subscription.ErrSubscriptionNotFound{"testid"}) } func TestDeleteSubscription_DeleteEndpointOK(t *testing.T) { diff --git a/libkv/subscriptions_errors.go b/subscription/errors.go similarity index 64% rename from libkv/subscriptions_errors.go rename to subscription/errors.go index 84fe229..ee7fa49 100644 --- a/libkv/subscriptions_errors.go +++ b/subscription/errors.go @@ -1,14 +1,21 @@ -package libkv +package subscription import ( "fmt" - - "github.com/serverless/event-gateway/subscription" ) +// ErrSubscriptionNotFound occurs when subscription cannot be found. +type ErrSubscriptionNotFound struct { + ID ID +} + +func (e ErrSubscriptionNotFound) Error() string { + return fmt.Sprintf("Subscription %q not found.", e.ID) +} + // ErrSubscriptionAlreadyExists occurs when subscription with the same ID already exists. type ErrSubscriptionAlreadyExists struct { - ID subscription.ID + ID ID } func (e ErrSubscriptionAlreadyExists) Error() string { @@ -17,36 +24,18 @@ func (e ErrSubscriptionAlreadyExists) Error() string { // ErrSubscriptionValidation occurs when subscription payload doesn't validate. type ErrSubscriptionValidation struct { - original string + Original string } func (e ErrSubscriptionValidation) Error() string { - return fmt.Sprintf("Subscription doesn't validate. Validation error: %q", e.original) -} - -// ErrSubscriptionNotFound occurs when subscription cannot be found. -type ErrSubscriptionNotFound struct { - ID subscription.ID -} - -func (e ErrSubscriptionNotFound) Error() string { - return fmt.Sprintf("Subscription %q not found.", e.ID) -} - -// ErrFunctionNotFound occurs when subscription cannot be created because backing function doesn't exist. -type ErrFunctionNotFound struct { - functionID string -} - -func (e ErrFunctionNotFound) Error() string { - return fmt.Sprintf("Function %q not found.", e.functionID) + return fmt.Sprintf("Subscription doesn't validate. Validation error: %q", e.Original) } // ErrPathConfict occurs when HTTP subscription path conflicts with existing path. type ErrPathConfict struct { - original string + Original string } func (e ErrPathConfict) Error() string { - return fmt.Sprintf("Subscription path conflict: %s.", e.original) + return fmt.Sprintf("Subscription path conflict: %s.", e.Original) }