Skip to content

Commit

Permalink
fix: extract inernal server error
Browse files Browse the repository at this point in the history
  • Loading branch information
J0 committed Apr 12, 2024
1 parent 96d2708 commit 88ba493
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions internal/api/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,6 @@ func (a *API) invokeHook(ctx context.Context, conn *storage.Connection, r *http.
if httpCode == 0 {
httpCode = http.StatusInternalServerError
}

httpError := &HTTPError{
HTTPStatus: httpCode,
Message: err.Error(),
Expand All @@ -339,7 +338,6 @@ func (a *API) invokeHook(ctx context.Context, conn *storage.Connection, r *http.
return nil
}

// TODO: make response generic
func (a *API) runHook(r *http.Request, conn *storage.Connection, hookConfig conf.ExtensibilityPointConfiguration, input, output any, scheme string) ([]byte, error) {
// TODO: Temp stopgap unitl custom access token has request
var ctx context.Context
Expand All @@ -348,23 +346,19 @@ func (a *API) runHook(r *http.Request, conn *storage.Connection, hookConfig conf
} else {
ctx = context.Background()
}

var response []byte
var err error
switch strings.ToLower(scheme) {
case "http", "https":
response, err = a.runHTTPHook(r, hookConfig, input, output)
if err != nil {
return nil, internalServerError("Error running Send Email hook.").WithInternalError(err)
}
return response, nil

case "pg-functions":
response, err = a.runPostgresHook(ctx, conn, hookConfig, input, output)
if err != nil {
return nil, err
}
return response, nil
default:
return nil, fmt.Errorf("only postgres hooks and HTTPS functions are supported at the moment")
}
if err != nil {
return nil, internalServerError("Error running hook URI: %v", hookConfig.URI).WithInternalError(err)
}
return response, nil
}

0 comments on commit 88ba493

Please sign in to comment.