Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

Return on realm lookup error #829

Merged
merged 2 commits into from
Oct 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions cmd/server/assets/400.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{{define "400"}}
<!doctype html>
<html lang="en">
<head>
{{template "head" .}}
</head>

<body>
<main role="main" class="container mt-5">
<h1>Not found</h1>
<p>
The page you requested does not exist.
</p>
</main>
</body>
</html>
{{end}}
15 changes: 15 additions & 0 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,21 @@ func InternalError(w http.ResponseWriter, r *http.Request, h *render.Renderer, e
}
}

// NotFound returns an error indicating the URL was not found.
func NotFound(w http.ResponseWriter, r *http.Request, h *render.Renderer) {
accept := strings.Split(r.Header.Get("Accept"), ",")
accept = append(accept, strings.Split(r.Header.Get("Content-Type"), ",")...)

switch {
case prefixInList(accept, ContentTypeHTML):
h.RenderHTMLStatus(w, http.StatusNotFound, "400", nil)
case prefixInList(accept, ContentTypeJSON):
h.RenderJSON(w, http.StatusNotFound, http.StatusText(http.StatusNotFound))
default:
http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
}
}

// Unauthorized returns an error indicating the request was unauthorized.
func Unauthorized(w http.ResponseWriter, r *http.Request, h *render.Renderer) {
accept := strings.Split(r.Header.Get("Accept"), ",")
Expand Down
7 changes: 7 additions & 0 deletions pkg/controller/redirect/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"strings"

"github.com/google/exposure-notifications-verification-server/pkg/controller"
"github.com/google/exposure-notifications-verification-server/pkg/database"
)

func (c *Controller) HandleIndex() http.Handler {
Expand All @@ -42,7 +43,13 @@ func (c *Controller) HandleIndex() http.Handler {
}
realm, err := c.db.FindRealmByRegion(hostRegion)
if err != nil {
if database.IsNotFound(err) {
controller.NotFound(w, r, c.h)
return
}

controller.InternalError(w, r, c.h, err)
return
}

// Get App Store Data.
Expand Down