diff --git a/cmd/adapter/main.go b/cmd/adapter/main.go index 0e860c3..1c88c60 100644 --- a/cmd/adapter/main.go +++ b/cmd/adapter/main.go @@ -16,7 +16,6 @@ import ( "github.com/beckn/beckn-onix/core/module" "github.com/beckn/beckn-onix/core/module/handler" "github.com/beckn/beckn-onix/pkg/log" - "github.com/beckn/beckn-onix/pkg/model" "github.com/beckn/beckn-onix/pkg/plugin" ) @@ -97,7 +96,7 @@ func newServer(ctx context.Context, mgr handler.PluginManager, cfg *Config) (htt mux := http.NewServeMux() err := module.Register(ctx, cfg.Modules, mux, mgr) if err != nil { - return nil, model.NewBadReqErr(fmt.Errorf("failed to register modules: %w", err)) + return nil, fmt.Errorf("failed to register modules: %w", err) } return mux, nil } diff --git a/core/module/client/registery.go b/core/module/client/registery.go index 22c2385..1fa0813 100644 --- a/core/module/client/registery.go +++ b/core/module/client/registery.go @@ -45,18 +45,18 @@ func (c *registryClient) Subscribe(ctx context.Context, subscription *model.Subs req, err := retryablehttp.NewRequest("POST", subscribeURL, bytes.NewBuffer(jsonData)) if err != nil { - return model.NewBadReqErr(fmt.Errorf("failed to create request: %w", err)) + return fmt.Errorf("failed to create request: %w", err) } req.Header.Set("Content-Type", "application/json") resp, err := c.client.Do(req) if err != nil { - return model.NewBadReqErr(fmt.Errorf("failed to send request with retry: %w", err)) + return fmt.Errorf("failed to send request with retry: %w", err) } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { - return model.NewBadReqErr(fmt.Errorf("subscribe request failed with status: %s", resp.Status)) + return fmt.Errorf("subscribe request failed with status: %s", resp.Status) } return nil } @@ -72,23 +72,23 @@ func (c *registryClient) Lookup(ctx context.Context, subscription *model.Subscri req, err := retryablehttp.NewRequest("POST", lookupURL, bytes.NewBuffer(jsonData)) if err != nil { - return nil, model.NewBadReqErr(fmt.Errorf("failed to create request: %w", err)) + return nil, fmt.Errorf("failed to create request: %w", err) } req.Header.Set("Content-Type", "application/json") resp, err := c.client.Do(req) if err != nil { - return nil, model.NewBadReqErr(fmt.Errorf("failed to send request with retry: %w", err)) + return nil, fmt.Errorf("failed to send request with retry: %w", err) } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { - return nil, model.NewBadReqErr(fmt.Errorf("lookup request failed with status: %s", resp.Status)) + return nil, fmt.Errorf("lookup request failed with status: %s", resp.Status) } body, err := io.ReadAll(resp.Body) if err != nil { - return nil, model.NewBadReqErr(fmt.Errorf("failed to read response body: %w", err)) + return nil, fmt.Errorf("failed to read response body: %w", err) } var results []model.Subscription diff --git a/core/module/handler/stdHandler.go b/core/module/handler/stdHandler.go index 091303a..251102e 100644 --- a/core/module/handler/stdHandler.go +++ b/core/module/handler/stdHandler.go @@ -178,12 +178,12 @@ func loadKeyManager(ctx context.Context, mgr PluginManager, cache definition.Cac return nil, nil } if cache == nil { - return nil, model.NewBadReqErr(fmt.Errorf("failed to load KeyManager plugin (%s): Cache plugin not configured", cfg.ID)) + return nil, fmt.Errorf("failed to load KeyManager plugin (%s): Cache plugin not configured", cfg.ID) } rClient := client.NewRegisteryClient(&client.Config{RegisteryURL: regURL}) km, err := mgr.KeyManager(ctx, cache, rClient, cfg) if err != nil { - return nil, model.NewBadReqErr(fmt.Errorf("failed to load cache plugin (%s): %w", cfg.ID, err)) + return nil, fmt.Errorf("failed to load cache plugin (%s): %w", cfg.ID, err) } log.Debugf(ctx, "Loaded Keymanager plugin: %s", cfg.ID) diff --git a/core/module/handler/step.go b/core/module/handler/step.go index b172d81..936ee98 100644 --- a/core/module/handler/step.go +++ b/core/module/handler/step.go @@ -105,7 +105,7 @@ func (s *validateSignStep) validate(ctx *model.StepContext, value string) error headerParts := strings.Split(value, "|") ids := strings.Split(headerParts[0], "\"") if len(ids) < 2 || len(headerParts) < 3 { - return model.NewBadReqErr(fmt.Errorf("malformed sign header")) + return fmt.Errorf("malformed sign header") } subID := ids[1] keyID := headerParts[1] @@ -114,7 +114,7 @@ func (s *validateSignStep) validate(ctx *model.StepContext, value string) error return fmt.Errorf("failed to get validation key: %w", err) } if err := s.validator.Validate(ctx, ctx.Body, value, key); err != nil { - return model.NewSignValidationErr(fmt.Errorf("sign validation failed: %w", err)) + return fmt.Errorf("sign validation failed: %w", err) } return nil } @@ -136,7 +136,7 @@ func newValidateSchemaStep(schemaValidator definition.SchemaValidator) (definiti // Run executes the schema validation step. func (s *validateSchemaStep) Run(ctx *model.StepContext) error { if err := s.validator.Validate(ctx, ctx.Request.URL, ctx.Body); err != nil { - return err.(*model.SchemaValidationErr).BecknError() + return fmt.Errorf("schema validation failed: %w", err) } return nil }