diff options
| -rw-r--r-- | backend/api/routes.go | 7 | ||||
| -rw-r--r-- | backend/db/db.go | 9 | ||||
| -rw-r--r-- | frontend/src/components/NewPaste.js | 13 |
3 files changed, 17 insertions, 12 deletions
diff --git a/backend/api/routes.go b/backend/api/routes.go index f8d2e4f..ff43714 100644 --- a/backend/api/routes.go +++ b/backend/api/routes.go @@ -38,7 +38,8 @@ func insertFunc(w http.ResponseWriter, r *http.Request) { hash, err := db.New(ip, content, expiry, title, password) if err != nil { w.WriteHeader(http.StatusBadRequest) - fmt.Fprintf(w, "got err: %s", err.Error()) + fmt.Fprintf(w, "%s", err.Error()) + return } // if successful return paste hash @@ -75,14 +76,14 @@ func handleGetPaste(w http.ResponseWriter, r *http.Request, parsedPassword strin // if hash was not found if err == cache.PasteNotFound { w.WriteHeader(http.StatusNotFound) - fmt.Fprintf(w, "got err: %s", err) + fmt.Fprintf(w, "%s", err) return } // if paste is password protected if err == cache.UserUnauthorized { w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintf(w, "got err: %s", err) + fmt.Fprintf(w, "%s", err) return } diff --git a/backend/db/db.go b/backend/db/db.go index 9bfe55a..6fbc5aa 100644 --- a/backend/db/db.go +++ b/backend/db/db.go @@ -80,16 +80,11 @@ func New(ip, content, expiry, title, password string) (string, error) { } func checkLengths(title string, content string) error { - errs := "" if len(title) > TitleLimit { - errs += fmt.Sprintf("title is longer than character limit of %d\n", TitleLimit) + return fmt.Errorf("title is longer than character limit of %d\n", TitleLimit) } if len(content) > ContentLimit { - errs += fmt.Sprintf("content is longer than character limit of %d\n", ContentLimit) - } - // if any errors were found - if errs != "" { - return fmt.Errorf(errs) + return fmt.Errorf("content is longer than character limit of %d\n", ContentLimit) } return nil diff --git a/frontend/src/components/NewPaste.js b/frontend/src/components/NewPaste.js index 29ae9ca..2ce2ecf 100644 --- a/frontend/src/components/NewPaste.js +++ b/frontend/src/components/NewPaste.js @@ -111,8 +111,17 @@ class NewPaste extends React.Component { }).then((response) => { // on success, redir this.setState({ hash: response.data.hash }) - }).catch((response) => { - this.newErr(response) + }).catch((error) => { + const resp = error.response + + // some weird err + if (resp !== undefined) { + const errTxt = `${resp.statusText}: ${resp.data}` + this.newErr(errTxt) + } else { + // some weird err (e.g. network) + this.newErr(error) + } }); event.preventDefault(); |