1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-24 23:59:47 +02:00

keycloak aiurth service JS code refactoring

This commit is contained in:
Harvey Kandola 2017-03-20 17:56:15 +00:00
parent 0f9d673eb5
commit 0fedfb199b
7 changed files with 88 additions and 79 deletions

View file

@ -89,7 +89,7 @@ func AuthenticateKeycloak(w http.ResponseWriter, r *http.Request) {
// Decode and verify Keycloak JWT
claims, err := decodeKeycloakJWT(a.Token, pk)
if err != nil {
writeServerError(w, method, err)
util.WriteRequestError(w, err.Error())
return
}

View file

@ -146,7 +146,6 @@ func WriteMarshalError(w http.ResponseWriter, err error) {
w.WriteHeader(http.StatusBadRequest)
_, err2 := w.Write([]byte("{Error: 'JSON marshal failed'}"))
log.IfErr(err2)
log.Error("Failed to JSON marshal", err)
}
// WriteJSON serializes data as JSON to HTTP response.
@ -165,6 +164,15 @@ func WriteJSON(w http.ResponseWriter, v interface{}) {
log.IfErr(err)
}
// WriteRequestError sends custom error message.
func WriteRequestError(w http.ResponseWriter, msg string) {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(http.StatusBadRequest)
_, err := w.Write([]byte(fmt.Sprintf("{Error: '%s'}", msg)))
log.IfErr(err)
}
// WriteBadLicense writes 402 when license is invalid
func WriteBadLicense(w http.ResponseWriter) {
w.Header().Set("Content-Type", "application/json; charset=utf-8")