From eb81344036b00b4984b5bfa0c9b3a1a964d003ac Mon Sep 17 00:00:00 2001 From: Jan-Lukas Else Date: Thu, 7 Nov 2019 11:44:52 +0100 Subject: [PATCH] Return error message when creating entry failed --- main.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 053c7a9..b4b9ae1 100644 --- a/main.go +++ b/main.go @@ -44,9 +44,13 @@ func handleMicroPub(w http.ResponseWriter, r *http.Request) { } bodyString := string(bodyBytes) entry, err := CreateEntry(contentType, bodyString) - if entry == nil { + if err != nil || entry == nil { w.WriteHeader(http.StatusBadRequest) - _, _ = w.Write([]byte("There was an error creating the entry")) + if err != nil { + _, _ = w.Write([]byte(err.Error())) + } else { + _, _ = w.Write([]byte("There was an error creating the entry")) + } return } if CheckAuthorization(entry, r.Header.Get("authorization")) {