mirror of
https://github.com/dutchcoders/transfer.sh.git
synced 2024-12-26 12:20:19 +01:00
improving error handling
This commit is contained in:
parent
09c9f4d866
commit
3f81515cd2
1 changed files with 4 additions and 3 deletions
|
@ -83,12 +83,13 @@ func previewHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
var reader io.ReadCloser
|
var reader io.ReadCloser
|
||||||
if reader, _, _, err = storage.Get(token, filename); err != nil {
|
if reader, _, _, err = storage.Get(token, filename); err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var data []byte
|
var data []byte
|
||||||
if data, err = ioutil.ReadAll(reader); err != nil {
|
if data, err = ioutil.ReadAll(reader); err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(contentType, "text/x-markdown") || strings.HasPrefix(contentType, "text/markdown") {
|
if strings.HasPrefix(contentType, "text/x-markdown") || strings.HasPrefix(contentType, "text/markdown") {
|
||||||
|
@ -266,6 +267,7 @@ func scanHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
response, err := c.ScanStream(reader)
|
response, err := c.ScanStream(reader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), 500)
|
http.Error(w, err.Error(), 500)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var b string
|
var b string
|
||||||
|
@ -321,7 +323,6 @@ func putHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
n, err = io.Copy(file, io.MultiReader(&b, f))
|
n, err = io.Copy(file, io.MultiReader(&b, f))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.Remove(file.Name())
|
os.Remove(file.Name())
|
||||||
|
|
||||||
log.Print(err)
|
log.Print(err)
|
||||||
http.Error(w, err.Error(), 500)
|
http.Error(w, err.Error(), 500)
|
||||||
return
|
return
|
||||||
|
@ -348,8 +349,8 @@ func putHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if err = storage.Put(token, filename, reader, contentType, uint64(contentLength)); err != nil {
|
if err = storage.Put(token, filename, reader, contentType, uint64(contentLength)); err != nil {
|
||||||
log.Printf("Error during save: %s", err.Error())
|
|
||||||
http.Error(w, errors.New("Could not save file").Error(), 500)
|
http.Error(w, errors.New("Could not save file").Error(), 500)
|
||||||
|
log.Printf(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue