Skip to content

Commit

Permalink
Fix #540 Return null response if there is no idp configured in servic…
Browse files Browse the repository at this point in the history
…e read idp
  • Loading branch information
albinpa authored and georgepadayatti committed Nov 13, 2023
1 parent 9bc3a86 commit c7579be
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions internal/handler/v2/service/service_read_idp.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package service

import (
"encoding/json"
"fmt"
"net/http"

"github.com/bb-consent/api/internal/common"
"github.com/bb-consent/api/internal/config"
"github.com/bb-consent/api/internal/idp"
"github.com/gorilla/mux"
)

type serviceIdp struct {
Expand All @@ -24,7 +21,7 @@ type serviceIdp struct {
}

type readIdpResp struct {
Idp serviceIdp `json:"idp"`
Idp interface{} `json:"idp"`
}

// ServiceReadIdp
Expand All @@ -34,18 +31,16 @@ func ServiceReadIdp(w http.ResponseWriter, r *http.Request) {
organisationId := r.Header.Get(config.OrganizationId)
organisationId = common.Sanitize(organisationId)

// Path params
idpId := mux.Vars(r)[config.IdpId]
idpId = common.Sanitize(idpId)

// Repository
idpRepo := idp.IdentityProviderRepository{}
idpRepo.Init(organisationId)

idp, err := idpRepo.GetByOrgId()
if err != nil {
m := fmt.Sprintf("Failed to fetch identity provider: %v", idpId)
common.HandleErrorV2(w, http.StatusInternalServerError, m, err)
resp := readIdpResp{
Idp: nil,
}
common.ReturnHTTPResponse(resp, w)
return
}
idpResp := serviceIdp{
Expand All @@ -63,8 +58,5 @@ func ServiceReadIdp(w http.ResponseWriter, r *http.Request) {
resp := readIdpResp{
Idp: idpResp,
}
response, _ := json.Marshal(resp)
w.Header().Set(config.ContentTypeHeader, config.ContentTypeJSON)
w.WriteHeader(http.StatusOK)
w.Write(response)
common.ReturnHTTPResponse(resp, w)
}

0 comments on commit c7579be

Please sign in to comment.