From ef26cdc13a0ad89a00758cb4ad74845d8b0c18e1 Mon Sep 17 00:00:00 2001 From: Hugo <hnouts@grandlyon.com> Date: Wed, 17 Feb 2021 16:03:09 +0100 Subject: [PATCH] catch enedis redirect error (code 500 . no state) catches error 500 from enedis instead of stopping at missing parameter (state) --- main.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index b27b4cd..4e6ea94 100644 --- a/main.go +++ b/main.go @@ -322,6 +322,21 @@ func main() { log.Info("WL - EnedisSuccess - Redirect - Redirecting user to Cozy stack") http.Redirect(w, r, redir, 302) } else { + if len(code) > 0 { + if findItem(statusCodes, code) { + intCode, err := strconv.Atoi(code) + if err != nil { + logRoute("Proxy_error_enedis_redirect") + log.Error("WL - ProxyError - Enedis - Redirect - String to int convert error for status code: ", err) + http.Error(w, http.StatusText(500), 500) + return + } + logRoute("Enedis_redirect_error") + log.Error("WL - EnedisError - Redirect - status code error: ", code) + http.Error(w, http.StatusText(intCode), intCode) + return + } + } logRoute("Proxy_error_enedis_redirect") log.Error("WL - ProxyError - Enedis - Redirect - Missing parameters in request") http.Error(w, http.StatusText(500), 500) @@ -504,7 +519,7 @@ func main() { clientSecret := "" code := "" grantType := "" - scope := "" + // scope := "" redirectUri := *cozyProxyURI + "/redirect-grdf" pce := "" IdToken := "" -- GitLab