always update source credential when doing unsafe raw request.
This commit is contained in:
parent
0ddfe68636
commit
13e21b580b
|
@ -1,7 +1,6 @@
|
||||||
package handler
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"github.com/fastenhealth/fasten-onprem/backend/pkg"
|
"github.com/fastenhealth/fasten-onprem/backend/pkg"
|
||||||
"github.com/fastenhealth/fasten-onprem/backend/pkg/config"
|
"github.com/fastenhealth/fasten-onprem/backend/pkg/config"
|
||||||
"github.com/fastenhealth/fasten-onprem/backend/pkg/database"
|
"github.com/fastenhealth/fasten-onprem/backend/pkg/database"
|
||||||
|
@ -65,6 +64,23 @@ func UnsafeRequestSource(c *gin.Context) {
|
||||||
//make sure we include all query string parameters with the raw request.
|
//make sure we include all query string parameters with the raw request.
|
||||||
parsedUrl.RawQuery = c.Request.URL.Query().Encode()
|
parsedUrl.RawQuery = c.Request.URL.Query().Encode()
|
||||||
|
|
||||||
|
//make sure we store the source credential information in the database, even if the request fails
|
||||||
|
defer func() {
|
||||||
|
//update source incase the access token/refresh token has been updated
|
||||||
|
sourceCredential := client.GetSourceCredential()
|
||||||
|
sourceCredentialConcrete, ok := sourceCredential.(*models.SourceCredential)
|
||||||
|
if !ok {
|
||||||
|
logger.Errorln("An error occurred while updating source credential, source credential is not of type *models.SourceCredential")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = databaseRepo.UpdateSource(c, sourceCredentialConcrete)
|
||||||
|
if err != nil {
|
||||||
|
logger.Errorf("An error occurred while updating source credential: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
logger.Info("Successfully updated source credential")
|
||||||
|
}()
|
||||||
|
|
||||||
_, err = client.GetRequest(parsedUrl.String(), &resp)
|
_, err = client.GetRequest(parsedUrl.String(), &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorf("Error making raw request, %v", err)
|
logger.Errorf("Error making raw request, %v", err)
|
||||||
|
@ -72,21 +88,6 @@ func UnsafeRequestSource(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//update source incase the access token/refresh token has been updated
|
|
||||||
sourceCredential := client.GetSourceCredential()
|
|
||||||
sourceCredentialConcrete, ok := sourceCredential.(*models.SourceCredential)
|
|
||||||
if !ok {
|
|
||||||
logger.Errorln("An error occurred while updating source credential, source credential is not of type *models.SourceCredential")
|
|
||||||
c.JSON(http.StatusOK, gin.H{"success": false, "data": resp, "error": fmt.Errorf("An error occurred while updating source credential, source credential is not of type *models.SourceCredential")})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
err = databaseRepo.UpdateSource(c, sourceCredentialConcrete)
|
|
||||||
if err != nil {
|
|
||||||
logger.Errorf("An error occurred while updating source credential: %v", err)
|
|
||||||
c.JSON(http.StatusOK, gin.H{"success": false, "data": resp, "error": fmt.Errorf("An error occurred while updating source credential: %v", err)})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{"success": true, "data": resp})
|
c.JSON(http.StatusOK, gin.H{"success": true, "data": resp})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue