40 lines
804 B
Go
40 lines
804 B
Go
|
package apiv1
|
||
|
|
||
|
import (
|
||
|
"log"
|
||
|
"net/http"
|
||
|
|
||
|
"github.com/go-chi/render"
|
||
|
)
|
||
|
|
||
|
func errNotFound() render.Renderer {
|
||
|
return &errResponse{
|
||
|
HTTPStatusCode: http.StatusNotFound,
|
||
|
StatusText: "Resource not found",
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func errInvalidRequest(err error) render.Renderer {
|
||
|
return &errResponse{
|
||
|
Err: err,
|
||
|
HTTPStatusCode: http.StatusBadRequest,
|
||
|
StatusText: "Invalid request",
|
||
|
ErrorText: err.Error(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func errRender(err error) render.Renderer {
|
||
|
return &errResponse{
|
||
|
Err: err,
|
||
|
HTTPStatusCode: http.StatusUnprocessableEntity,
|
||
|
StatusText: "Error rendering response",
|
||
|
ErrorText: err.Error(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func renderResponse(w http.ResponseWriter, r *http.Request, v render.Renderer) {
|
||
|
if err := render.Render(w, r, v); err != nil {
|
||
|
log.Fatal(err)
|
||
|
}
|
||
|
}
|