1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-24 15:59:41 +02:00

chore(handlers): replace structs by functions for HTTP errors EE-4227 (#7664)

This commit is contained in:
andres-portainer 2022-09-14 20:42:39 -03:00 committed by GitHub
parent 7accdf704c
commit 9ef5636718
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
157 changed files with 1123 additions and 1147 deletions

View file

@ -29,17 +29,17 @@ import (
func (handler *Handler) uploadTLS(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
certificate, err := request.RetrieveRouteVariableValue(r, "certificate")
if err != nil {
return &httperror.HandlerError{http.StatusBadRequest, "Invalid certificate route variable", err}
return httperror.BadRequest("Invalid certificate route variable", err)
}
folder, err := request.RetrieveMultiPartFormValue(r, "folder", false)
if err != nil {
return &httperror.HandlerError{http.StatusBadRequest, "Invalid query parameter: folder", err}
return httperror.BadRequest("Invalid query parameter: folder", err)
}
file, _, err := request.RetrieveMultiPartFormFile(r, "file")
if err != nil {
return &httperror.HandlerError{http.StatusBadRequest, "Invalid certificate file. Ensure that the certificate file is uploaded correctly", err}
return httperror.BadRequest("Invalid certificate file. Ensure that the certificate file is uploaded correctly", err)
}
var fileType portainer.TLSFileType
@ -51,12 +51,12 @@ func (handler *Handler) uploadTLS(w http.ResponseWriter, r *http.Request) *httpe
case "key":
fileType = portainer.TLSFileKey
default:
return &httperror.HandlerError{http.StatusBadRequest, "Invalid certificate route value. Value must be one of: ca, cert or key", filesystem.ErrUndefinedTLSFileType}
return httperror.BadRequest("Invalid certificate route value. Value must be one of: ca, cert or key", filesystem.ErrUndefinedTLSFileType)
}
_, err = handler.FileService.StoreTLSFileFromBytes(folder, fileType, file)
if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist certificate file on disk", err}
return httperror.InternalServerError("Unable to persist certificate file on disk", err)
}
return response.Empty(w)