@@ -10,7 +10,7 @@ import (
1010
1111 "github.com/ginaxu1/gov-dx-sandbox/exchange/orchestration-engine/logger"
1212 "github.com/ginaxu1/gov-dx-sandbox/exchange/orchestration-engine/pkg/auth"
13- "github.com/gov-dx-sandbox/exchange/pkg /monitoring"
13+ "github.com/gov-dx-sandbox/exchange/shared /monitoring"
1414 "golang.org/x/oauth2/clientcredentials"
1515)
1616
@@ -49,7 +49,7 @@ func NewProvider(serviceKey, serviceUrl, schemaID string, authConfig *auth.AuthC
4949}
5050
5151// PerformRequest performs the HTTP request to the provider with necessary authentication.
52- func (p * Provider ) PerformRequest (ctx context.Context , reqBody []byte ) (* http.Response , error ) {
52+ func (p * Provider ) PerformRequest (ctx context.Context , reqBody []byte ) (resp * http.Response , err error ) {
5353 // 1. Create Request
5454 req , err := http .NewRequestWithContext (ctx , "POST" , p .ServiceUrl , bytes .NewBuffer (reqBody ))
5555 if err != nil {
@@ -59,19 +59,21 @@ func (p *Provider) PerformRequest(ctx context.Context, reqBody []byte) (*http.Re
5959 req .Header .Set ("Content-Type" , "application/json" )
6060
6161 start := time .Now ()
62+ defer func () {
63+ monitoring .RecordExternalCall (p .ServiceKey , "provider_request" , time .Since (start ), err )
64+ }()
6265
6366 if p .Auth != nil {
6467 switch p .Auth .Type {
6568 case auth .AuthTypeOAuth2 :
6669 if p .OAuth2Config == nil {
67- logger .Log .Error ("OAuth2Config is nil" , "providerKey" , p .ServiceKey )
68- return nil , fmt .Errorf ("OAuth2Config is nil" )
70+ err = fmt .Errorf ("OAuth2Config is nil" )
71+ logger .Log .Error (err .Error (), "providerKey" , p .ServiceKey )
72+ return nil , err
6973 }
7074
7175 client := p .OAuth2Config .Client (ctx )
72- resp , err := client .Do (req ) // Use context with request
73- monitoring .RecordExternalCall (p .ServiceKey , "provider_request" , time .Since (start ), err )
74- return resp , err
76+ return client .Do (req )
7577 case auth .AuthTypeAPIKey :
7678 req .Header .Set (p .Auth .APIKeyName , p .Auth .APIKeyValue )
7779 }
0 commit comments