Add structured logging and better error handling
This commit is contained in:
1 parent
db4e3c9611
commit
68c7dd76f2
31 files changed
+640
-109
No files matched your search
@@ -23,10 +23,10 @@ func (server *Server) handleLibraries(writer http.ResponseWriter, _ *http.Reques
|
||||
writeJSON(writer, http.StatusOK, server.manager.Destinations())
|
||||
}
|
||||
|
||||
func (server *Server) handleDisk(writer http.ResponseWriter, _ *http.Request) {
|
||||
func (server *Server) handleDisk(writer http.ResponseWriter, request *http.Request) {
|
||||
available, err := server.manager.AvailableBytes()
|
||||
if err != nil {
|
||||
writeFailure(writer, err)
|
||||
writeFailure(writer, request, err)
|
||||
return
|
||||
}
|
||||
writeJSON(writer, http.StatusOK, diskResponse{AvailableBytes: available, ReservedBytes: server.manager.Preferences().MinFreeBytes()})
|
||||
@@ -38,13 +38,12 @@ func (server *Server) handleListJobs(writer http.ResponseWriter, _ *http.Request
|
||||
|
||||
func (server *Server) handleCreateJob(writer http.ResponseWriter, request *http.Request) {
|
||||
var body jobs.CreateRequest
|
||||
if err := decodeJSON(request, &body); err != nil {
|
||||
writeError(writer, http.StatusBadRequest, "invalid request body")
|
||||
if !decodeBody(writer, request, &body) {
|
||||
return
|
||||
}
|
||||
snapshot, err := server.manager.Create(body)
|
||||
if err != nil {
|
||||
writeFailure(writer, err)
|
||||
writeFailure(writer, request, err)
|
||||
return
|
||||
}
|
||||
writeJSON(writer, http.StatusCreated, snapshot)
|
||||
@@ -53,7 +52,7 @@ func (server *Server) handleCreateJob(writer http.ResponseWriter, request *http.
|
||||
func (server *Server) handleJobFiles(writer http.ResponseWriter, request *http.Request) {
|
||||
tree, err := server.manager.Files(request.PathValue("id"))
|
||||
if err != nil {
|
||||
writeFailure(writer, err)
|
||||
writeFailure(writer, request, err)
|
||||
return
|
||||
}
|
||||
writeJSON(writer, http.StatusOK, tree)
|
||||
@@ -61,12 +60,11 @@ func (server *Server) handleJobFiles(writer http.ResponseWriter, request *http.R
|
||||
|
||||
func (server *Server) handleExtract(writer http.ResponseWriter, request *http.Request) {
|
||||
var body extractRequest
|
||||
if err := decodeJSON(request, &body); err != nil {
|
||||
writeError(writer, http.StatusBadRequest, "invalid request body")
|
||||
if !decodeBody(writer, request, &body) {
|
||||
return
|
||||
}
|
||||
if err := server.manager.Extract(request.PathValue("id"), body.Path); err != nil {
|
||||
writeFailure(writer, err)
|
||||
writeFailure(writer, request, err)
|
||||
return
|
||||
}
|
||||
writeJSON(writer, http.StatusAccepted, startedResponse{Started: true})
|
||||
@@ -74,12 +72,11 @@ func (server *Server) handleExtract(writer http.ResponseWriter, request *http.Re
|
||||
|
||||
func (server *Server) handleMove(writer http.ResponseWriter, request *http.Request) {
|
||||
var body jobs.MoveRequest
|
||||
if err := decodeJSON(request, &body); err != nil {
|
||||
writeError(writer, http.StatusBadRequest, "invalid request body")
|
||||
if !decodeBody(writer, request, &body) {
|
||||
return
|
||||
}
|
||||
if err := server.manager.Move(request.PathValue("id"), body); err != nil {
|
||||
writeFailure(writer, err)
|
||||
writeFailure(writer, request, err)
|
||||
return
|
||||
}
|
||||
writeJSON(writer, http.StatusAccepted, startedResponse{Started: true})
|
||||
@@ -87,7 +84,7 @@ func (server *Server) handleMove(writer http.ResponseWriter, request *http.Reque
|
||||
|
||||
func (server *Server) handleDeleteJob(writer http.ResponseWriter, request *http.Request) {
|
||||
if err := server.manager.Delete(request.PathValue("id")); err != nil {
|
||||
writeFailure(writer, err)
|
||||
writeFailure(writer, request, err)
|
||||
return
|
||||
}
|
||||
writer.WriteHeader(http.StatusNoContent)
|
||||
|
||||
Reference in new issue
Block a user