Skip to content
Snippets Groups Projects
Commit 4b28ec98 authored by Rémi PAILHAREY's avatar Rémi PAILHAREY :fork_knife_plate:
Browse files

Merge branch 'fix/get-consent-by-id-500' into 'dev'

Fix/get consent by id 500

See merge request web-et-numerique/llle_project/backoffice-server!37
parents c463107f bddfcd66
Branches
No related tags found
4 merge requests!73Deploy Openshift v2,!65MEP: removed Meilisearch,!52back-office SGE before canary release,!37Fix/get consent by id 500
Pipeline #42324 passed
...@@ -2,6 +2,7 @@ package models ...@@ -2,6 +2,7 @@ package models
import ( import (
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"log" "log"
"net/http" "net/http"
...@@ -34,7 +35,11 @@ func (dh *DataHandler) GetConsentById(w http.ResponseWriter, r *http.Request) { ...@@ -34,7 +35,11 @@ func (dh *DataHandler) GetConsentById(w http.ResponseWriter, r *http.Request) {
var consent Consent var consent Consent
err = dh.sqlClient.First(&consent, id).Error err = dh.sqlClient.First(&consent, id).Error
if err != nil { if err != nil {
http.Error(w, "couldn't find consent", http.StatusInternalServerError) if errors.Is(err, gorm.ErrRecordNotFound) {
http.Error(w, "consent not found", http.StatusNotFound)
return
}
http.Error(w, "error while finding consent", http.StatusInternalServerError)
return return
} }
......
...@@ -245,8 +245,10 @@ func sgeTests(t *testing.T) { ...@@ -245,8 +245,10 @@ func sgeTests(t *testing.T) {
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
// Try to update a consent (must pass) // Try to update a consent (must pass)
do("PUT", "/api/sge/consent/1", sgeApiHeader, `{"serviceId":123456}`, http.StatusOK, `{"ID":1`) do("PUT", "/api/sge/consent/1", sgeApiHeader, `{"serviceId":123456}`, http.StatusOK, `{"ID":1`)
// Try to get a consent that doesn't exist (must fail not found)
do("GET", "/api/sge/consent/123456", sgeApiHeader, "", http.StatusNotFound, `consent not found`)
// Try to get a consent (must pass) // Try to get a consent (must pass)
do("GET", "/api/sge/consent/1", sgeApiHeader, `{"serviceId":123456}`, http.StatusOK, `{"ID":1`) do("GET", "/api/sge/consent/1", sgeApiHeader, "", http.StatusOK, `{"ID":1`)
// Try to login (must pass) // Try to login (must pass)
do("GET", "/OAuth2Login", noH, "", http.StatusOK, "") do("GET", "/OAuth2Login", noH, "", http.StatusOK, "")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment