(m KeyReportingManager, prod bool)
| 822 | } |
| 823 | |
| 824 | func getGetKeyReportingHandler(m KeyReportingManager, prod bool) gin.HandlerFunc { |
| 825 | return func(c *gin.Context) { |
| 826 | log := util.GetLogFromCtx(c) |
| 827 | telemetry.Incr("bricksllm.admin.get_get_key_reporting_hanlder.requests", nil, 1) |
| 828 | |
| 829 | start := time.Now() |
| 830 | defer func() { |
| 831 | dur := time.Since(start) |
| 832 | telemetry.Timing("bricksllm.admin.get_get_key_reporting_hanlder.latency", dur, nil, 1) |
| 833 | }() |
| 834 | |
| 835 | path := "/api/reporting/keys/:id" |
| 836 | if c == nil || c.Request == nil { |
| 837 | c.JSON(http.StatusInternalServerError, &ErrorResponse{ |
| 838 | Type: "/errors/empty-context", |
| 839 | Title: "context is empty error", |
| 840 | Status: http.StatusInternalServerError, |
| 841 | Detail: "gin context is empty", |
| 842 | Instance: path, |
| 843 | }) |
| 844 | return |
| 845 | } |
| 846 | |
| 847 | id := c.Param("id") |
| 848 | if len(id) == 0 { |
| 849 | c.JSON(http.StatusBadRequest, &ErrorResponse{ |
| 850 | Type: "/errors/missing-param-id", |
| 851 | Title: "id is empty", |
| 852 | Status: http.StatusBadRequest, |
| 853 | Detail: "id url param is missing from the request url. it is required for retrieving api key reporting", |
| 854 | Instance: path, |
| 855 | }) |
| 856 | |
| 857 | return |
| 858 | } |
| 859 | |
| 860 | kr, err := m.GetKeyReporting(id) |
| 861 | if err != nil { |
| 862 | errType := "internal" |
| 863 | |
| 864 | defer func() { |
| 865 | telemetry.Incr("bricksllm.admin.get_get_key_reporting_hanlder.get_key_reporting_error", []string{ |
| 866 | "error_type:" + errType, |
| 867 | }, 1) |
| 868 | }() |
| 869 | |
| 870 | if _, ok := err.(notFoundError); ok { |
| 871 | errType = "not_found" |
| 872 | |
| 873 | logError(log, "key not found", prod, err) |
| 874 | c.JSON(http.StatusInternalServerError, &ErrorResponse{ |
| 875 | Type: "/errors/key-not-found", |
| 876 | Title: "key not found error", |
| 877 | Status: http.StatusNotFound, |
| 878 | Detail: err.Error(), |
| 879 | Instance: path, |
| 880 | }) |
| 881 | return |
no test coverage detected