mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-18 13:12:17 +01:00
now returing bad request if no file to convert
This commit is contained in:
@@ -19,11 +19,11 @@ type Converter struct {
|
|||||||
workingDir string
|
workingDir string
|
||||||
}
|
}
|
||||||
|
|
||||||
type noFileToConvertError struct{}
|
type NoFileToConvertError struct{}
|
||||||
|
|
||||||
const noFileToConvertErrorMessage = "No file to convert"
|
const noFileToConvertErrorMessage = "No file to convert"
|
||||||
|
|
||||||
func (e *noFileToConvertError) Error() string {
|
func (e *NoFileToConvertError) Error() string {
|
||||||
return noFileToConvertErrorMessage
|
return noFileToConvertErrorMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,7 +62,7 @@ func NewConverter(r *http.Request) (*Converter, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(c.files) == 0 {
|
if len(c.files) == 0 {
|
||||||
return c, &noFileToConvertError{}
|
return c, &NoFileToConvertError{}
|
||||||
}
|
}
|
||||||
|
|
||||||
return c, nil
|
return c, nil
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ func TestClear(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestNoFileToConvertError(t *testing.T) {
|
func TestNoFileToConvertError(t *testing.T) {
|
||||||
err := &noFileToConvertError{}
|
err := &NoFileToConvertError{}
|
||||||
if err.Error() != noFileToConvertErrorMessage {
|
if err.Error() != noFileToConvertErrorMessage {
|
||||||
t.Errorf("Error returned a wrong message: got '%s' want '%s'", err.Error(), noFileToConvertErrorMessage)
|
t.Errorf("Error returned a wrong message: got '%s' want '%s'", err.Error(), noFileToConvertErrorMessage)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,8 +60,12 @@ func convertHandler(next http.Handler) http.Handler {
|
|||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
c, err := converter.NewConverter(r)
|
c, err := converter.NewConverter(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO bad request if no file to convert
|
if _, ok := err.(*converter.NoFileToConvertError); ok {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
|
} else {
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
|
||||||
logger.Error(err)
|
logger.Error(err)
|
||||||
|
|
||||||
if c != nil {
|
if c != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user