Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package buildbot | 5 package buildbot |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "fmt" | 8 "fmt" |
| 9 "net/http" | 9 "net/http" |
| 10 "strconv" | 10 "strconv" |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 common.ErrorPage(c, http.StatusBadRequest, "No build number") | 31 common.ErrorPage(c, http.StatusBadRequest, "No build number") |
| 32 return | 32 return |
| 33 } | 33 } |
| 34 num, err := strconv.Atoi(buildNum) | 34 num, err := strconv.Atoi(buildNum) |
| 35 if err != nil { | 35 if err != nil { |
| 36 common.ErrorPage(c, http.StatusBadRequest, | 36 common.ErrorPage(c, http.StatusBadRequest, |
| 37 fmt.Sprintf("%s does not look like a number", buildNum)) | 37 fmt.Sprintf("%s does not look like a number", buildNum)) |
| 38 return | 38 return |
| 39 } | 39 } |
| 40 | 40 |
| 41 » result, err := build(c.Context, master, builder, num) | 41 » result, err := Build(c.Context, master, builder, num) |
| 42 if err != nil { | 42 if err != nil { |
| 43 var code int | 43 var code int |
| 44 switch err { | 44 switch err { |
| 45 case errBuildNotFound: | 45 case errBuildNotFound: |
| 46 code = http.StatusNotFound | 46 code = http.StatusNotFound |
| 47 case errNotAuth: | 47 case errNotAuth: |
| 48 code = http.StatusUnauthorized | 48 code = http.StatusUnauthorized |
| 49 default: | 49 default: |
| 50 code = http.StatusInternalServerError | 50 code = http.StatusInternalServerError |
| 51 } | 51 } |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 76 if err != nil { | 76 if err != nil { |
| 77 common.ErrorPage(c, http.StatusBadRequest, err.Error()) | 77 common.ErrorPage(c, http.StatusBadRequest, err.Error()) |
| 78 return | 78 return |
| 79 } | 79 } |
| 80 if limit < 0 { | 80 if limit < 0 { |
| 81 limit = 25 | 81 limit = 25 |
| 82 } | 82 } |
| 83 cursor := c.Request.FormValue("cursor") | 83 cursor := c.Request.FormValue("cursor") |
| 84 | 84 |
| 85 result, err := builderImpl(c.Context, master, builder, limit, cursor) | 85 result, err := builderImpl(c.Context, master, builder, limit, cursor) |
| 86 if err != nil { | 86 if err != nil { |
|
nodir
2017/05/26 18:33:05
we have 4 cases here essentially. I think using sw
Ryan Tseng
2017/05/26 22:49:22
I was reluctlant to do this because I wouldn't hav
| |
| 87 if _, ok := err.(errBuilderNotFound); ok { | |
| 88 common.ErrorPage(c, http.StatusNotFound, err.Error()) | |
| 89 return | |
| 90 } | |
| 91 if err == errNotAuth { | |
| 92 common.ErrorPage(c, http.StatusUnauthorized, err.Error() ) | |
| 93 return | |
| 94 } | |
| 87 common.ErrorPage(c, http.StatusInternalServerError, err.Error()) | 95 common.ErrorPage(c, http.StatusInternalServerError, err.Error()) |
| 88 return | 96 return |
| 89 } | 97 } |
| 90 | 98 |
| 91 // Render into the template | 99 // Render into the template |
| 92 templates.MustRender(c.Context, c.Writer, "pages/builder.html", template s.Args{ | 100 templates.MustRender(c.Context, c.Writer, "pages/builder.html", template s.Args{ |
| 93 "Builder": result, | 101 "Builder": result, |
| 94 }) | 102 }) |
| 95 } | 103 } |
| OLD | NEW |