auth

Paddy 2014-10-26 Parent:b3cd7765a7c8 Child:0cc717e02c9b

59:03c9890f99c5 Go to Latest

auth/http.go

Catch ErrClientNotFound. It's not a 500 error if the user specifies a Client that doesn't exist in the clientStore. That's a 400, with an error that should be rendered for the user.

History
     1.1 --- a/http.go	Sun Oct 26 03:22:41 2014 -0400
     1.2 +++ b/http.go	Sun Oct 26 03:31:24 2014 -0400
     1.3 @@ -28,10 +28,17 @@
     1.4  	}
     1.5  	client, err := context.GetClient(clientID)
     1.6  	if err != nil {
     1.7 -		w.WriteHeader(http.StatusInternalServerError)
     1.8 -		context.Render(w, getGrantTemplateName, map[string]interface{}{
     1.9 -			"internal_error": err,
    1.10 -		})
    1.11 +		if err == ErrClientNotFound {
    1.12 +			w.WriteHeader(http.StatusBadRequest)
    1.13 +			context.Render(w, getGrantTemplateName, map[string]interface{}{
    1.14 +				"error": "The Client specified couldn't be found.",
    1.15 +			})
    1.16 +		} else {
    1.17 +			w.WriteHeader(http.StatusInternalServerError)
    1.18 +			context.Render(w, getGrantTemplateName, map[string]interface{}{
    1.19 +				"internal_error": err,
    1.20 +			})
    1.21 +		}
    1.22  		return
    1.23  	}
    1.24  	// whether a redirect URI is valid or not depends on the number of endpoints