MCPcopy
hub / github.com/mudler/LocalAI / notFoundHandler

Function notFoundHandler

core/http/render.go:33–48  ·  view source on GitHub ↗
(c echo.Context)

Source from the content-addressed store, hash-verified

31}
32
33func notFoundHandler(c echo.Context) error {
34 // Check if the request accepts JSON
35 contentType := c.Request().Header.Get("Content-Type")
36 accept := c.Request().Header.Get("Accept")
37 if strings.Contains(contentType, "application/json") || !strings.Contains(accept, "text/html") {
38 // The client expects a JSON response
39 return c.JSON(http.StatusNotFound, schema.ErrorResponse{
40 Error: &schema.APIError{Message: "Resource not found", Code: http.StatusNotFound},
41 })
42 } else {
43 // The client expects an HTML response
44 return c.Render(http.StatusNotFound, "views/404", map[string]any{
45 "BaseURL": middleware.BaseURL(c),
46 })
47 }
48}
49
50func renderEngine() *TemplateRenderer {
51 // Parse all templates from embedded filesystem

Callers 1

APIFunction · 0.85

Calls 6

BaseURLFunction · 0.92
ContainsMethod · 0.80
JSONMethod · 0.80
GetMethod · 0.65
RequestMethod · 0.65
RenderMethod · 0.45

Tested by

no test coverage detected