handling case no file to convert

This commit is contained in:
Julien Neuhart
2018-04-11 09:58:36 +02:00
parent f59054b5e0
commit 6b5a214462
2 changed files with 36 additions and 6 deletions

View File

@@ -19,6 +19,14 @@ type Converter struct {
workingDir string
}
type noFileToConvertError struct{}
const noFileToConvertErrorMessage = "No file to convert"
func (e *noFileToConvertError) Error() string {
return noFileToConvertErrorMessage
}
// NewConverter instantiates a converter by parsing a request.
func NewConverter(r *http.Request) (*Converter, error) {
c := &Converter{
@@ -53,6 +61,10 @@ func NewConverter(r *http.Request) (*Converter, error) {
c.files = append(c.files, f)
}
if len(c.files) == 0 {
return c, &noFileToConvertError{}
}
return c, nil
}