Skip to content

Commit

Permalink
Add error responses to pfldapexplorer
Browse files Browse the repository at this point in the history
  • Loading branch information
VakarisZ authored and VakarisZ committed Jul 3, 2023
1 parent f2a945c commit 353e77d
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions go/caddy/pfldapexplorer/pfldapexplorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/go-chi/chi"
"github.com/inverse-inc/go-utils/log"
"github.com/inverse-inc/go-utils/sharedutils"
"github.com/inverse-inc/packetfence/go/api-frontend/unifiedapierrors"
"github.com/inverse-inc/packetfence/go/caddy/caddy"
"github.com/inverse-inc/packetfence/go/caddy/caddy/caddyhttp/httpserver"
"github.com/inverse-inc/packetfence/go/panichandler"
Expand Down Expand Up @@ -119,17 +120,23 @@ func (h *Handler) HandleLDAPSearchRequest(res http.ResponseWriter, req *http.Req
body, err := ioutil.ReadAll(req.Body)
if err != nil {
log.LoggerWContext(*h.Ctx).Info(err.Error())
unifiedapierrors.Error(res, err.Error(), http.StatusBadRequest)
return
}

if err = json.Unmarshal(body, &searchQuery); err != nil {
log.LoggerWContext(*h.Ctx).Info(err.Error())
unifiedapierrors.Error(res, err.Error(), http.StatusBadRequest)
return
}

ldapSearchServer := getLdapServerFromConfig(req.Context(), searchQuery.Server)
ldapSearchClient := LdapSearchClient{LdapServer: ldapSearchServer, Timeout: serverConnectionTimeout, LdapClientFactory: LdapClientFactory{}}
results, err := ldapSearchClient.SearchLdap(&searchQuery)
if err != nil {
log.LoggerWContext(*h.Ctx).Info(err.Error())
unifiedapierrors.Error(res, err.Error(), http.StatusBadRequest)
return
}

res.Header().Set("Content-Type", "application/json; charset=UTF-8")
Expand Down

0 comments on commit 353e77d

Please sign in to comment.