for errors during maildir/mbox zip/tgz import in account page, return http 400 for user errors (e.g. bad file format) and show the error message

This commit is contained in:
Mechiel Lukkien
2024-01-05 11:31:05 +01:00
parent 62db2af846
commit ac8256feb6
4 changed files with 20 additions and 16 deletions

View File

@ -306,10 +306,14 @@ func handle(apiHandler http.Handler, isForwarded bool, w http.ResponseWriter, r
http.Error(w, "500 - internal server error - "+err.Error(), http.StatusInternalServerError)
return
}
token, err := importStart(log, accName, tmpf, skipMailboxPrefix)
token, isUserError, err := importStart(log, accName, tmpf, skipMailboxPrefix)
if err != nil {
log.Errorx("starting import", err)
http.Error(w, "500 - internal server error - "+err.Error(), http.StatusInternalServerError)
log.Errorx("starting import", err, slog.Bool("usererror", isUserError))
if isUserError {
http.Error(w, "400 - bad request - "+err.Error(), http.StatusBadRequest)
} else {
http.Error(w, "500 - internal server error - "+err.Error(), http.StatusInternalServerError)
}
return
}
tmpf = nil // importStart is now responsible for cleanup.