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

fix: getting consent with unknown id now returns 404

parent c463107f
No related branches found
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
......@@ -2,6 +2,7 @@ package models
import (
"encoding/json"
"errors"
"fmt"
"log"
"net/http"
......@@ -34,7 +35,11 @@ func (dh *DataHandler) GetConsentById(w http.ResponseWriter, r *http.Request) {
var consent Consent
err = dh.sqlClient.First(&consent, id).Error
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
}
......
......@@ -245,8 +245,10 @@ func sgeTests(t *testing.T) {
time.Sleep(1 * time.Second)
// Try to update a consent (must pass)
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)
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)
do("GET", "/OAuth2Login", noH, "", http.StatusOK, "")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment