(m RouteManager, prod bool)
| 108 | } |
| 109 | |
| 110 | func getGetRouteHandler(m RouteManager, prod bool) gin.HandlerFunc { |
| 111 | return func(c *gin.Context) { |
| 112 | log := util.GetLogFromCtx(c) |
| 113 | telemetry.Incr("bricksllm.admin.get_get_route_handler.requests", nil, 1) |
| 114 | |
| 115 | start := time.Now() |
| 116 | defer func() { |
| 117 | dur := time.Since(start) |
| 118 | telemetry.Timing("bricksllm.admin.get_get_route_handler.latency", dur, nil, 1) |
| 119 | }() |
| 120 | |
| 121 | path := "/api/routes/:id" |
| 122 | if c == nil || c.Request == nil { |
| 123 | c.JSON(http.StatusInternalServerError, &ErrorResponse{ |
| 124 | Type: "/errors/empty-context", |
| 125 | Title: "context is empty error", |
| 126 | Status: http.StatusInternalServerError, |
| 127 | Detail: "gin context is empty", |
| 128 | Instance: path, |
| 129 | }) |
| 130 | return |
| 131 | } |
| 132 | |
| 133 | r, err := m.GetRoute(c.Param("id")) |
| 134 | if err != nil { |
| 135 | errType := "internal" |
| 136 | defer func() { |
| 137 | telemetry.Incr("bricksllm.admin.get_get_route_handler.get_route_err", []string{ |
| 138 | "error_type:" + errType, |
| 139 | }, 1) |
| 140 | }() |
| 141 | |
| 142 | if _, ok := err.(notFoundError); ok { |
| 143 | errType = "not_found" |
| 144 | |
| 145 | logError(log, "route not found", prod, err) |
| 146 | c.JSON(http.StatusNotFound, &ErrorResponse{ |
| 147 | Type: "/errors/route-not-found", |
| 148 | Title: "route not found error", |
| 149 | Status: http.StatusNotFound, |
| 150 | Detail: err.Error(), |
| 151 | Instance: path, |
| 152 | }) |
| 153 | return |
| 154 | } |
| 155 | |
| 156 | logError(log, "error when getting a route", prod, err) |
| 157 | c.JSON(http.StatusInternalServerError, &ErrorResponse{ |
| 158 | Type: "/errors/route-manager", |
| 159 | Title: "getting a route error", |
| 160 | Status: http.StatusInternalServerError, |
| 161 | Detail: err.Error(), |
| 162 | Instance: path, |
| 163 | }) |
| 164 | return |
| 165 | } |
| 166 | |
| 167 | telemetry.Incr("bricksllm.admin.get_get_route_handler.success", nil, 1) |
no test coverage detected