mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-16 04:12:16 +01:00
adding new error when files key does not exist in the form data
This commit is contained in:
@@ -27,6 +27,14 @@ func (e *NoFileToConvertError) Error() string {
|
|||||||
return "There is no file to convert"
|
return "There is no file to convert"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FilesKeyNotFoundError is raised when "files" key does not exist
|
||||||
|
// in the form data
|
||||||
|
type FilesKeyNotFoundError struct{}
|
||||||
|
|
||||||
|
func (e *FilesKeyNotFoundError) Error() string {
|
||||||
|
return "\"files\" key was not found in the form data"
|
||||||
|
}
|
||||||
|
|
||||||
// NewConverter instantiates a converter by parsing a request.
|
// NewConverter instantiates a converter by parsing a request.
|
||||||
func NewConverter(r *http.Request, contentType ghttp.ContentType) (*Converter, error) {
|
func NewConverter(r *http.Request, contentType ghttp.ContentType) (*Converter, error) {
|
||||||
c := &Converter{
|
c := &Converter{
|
||||||
@@ -47,7 +55,7 @@ func NewConverter(r *http.Request, contentType ghttp.ContentType) (*Converter, e
|
|||||||
formData := r.MultipartForm
|
formData := r.MultipartForm
|
||||||
files, ok := formData.File["files"]
|
files, ok := formData.File["files"]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, nil
|
return nil, &FilesKeyNotFoundError{}
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range files {
|
for i := range files {
|
||||||
|
|||||||
@@ -72,6 +72,8 @@ func convertHandler(next http.Handler) http.Handler {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
if noFileToConvertError, ok := err.(*converter.NoFileToConvertError); ok {
|
if noFileToConvertError, ok := err.(*converter.NoFileToConvertError); ok {
|
||||||
http.Error(w, noFileToConvertError.Error(), http.StatusBadRequest)
|
http.Error(w, noFileToConvertError.Error(), http.StatusBadRequest)
|
||||||
|
} else if filesKeyNotFoundError, ok := err.(*converter.FilesKeyNotFoundError); ok {
|
||||||
|
http.Error(w, filesKeyNotFoundError.Error(), http.StatusBadRequest)
|
||||||
} else {
|
} else {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user