-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed error handling for bookmarks manager (#137)
* Fixed error handling for bookmarks manager * add additional error message handling updates --------- Co-authored-by: Joe Freund <[email protected]> Co-authored-by: Leland Garofalo <[email protected]>
- Loading branch information
1 parent
bde8177
commit 68541dc
Showing
4 changed files
with
118 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package common | ||
|
||
import ( | ||
"encoding/json" | ||
"log" | ||
"net/http" | ||
) | ||
|
||
type Error struct { | ||
Error string `json:"error"` | ||
StatusCode int `json:"status_code"` | ||
} | ||
|
||
var InternalServerErrorMessage = "Internal Server Error" | ||
|
||
func WriteErrorJson(w http.ResponseWriter, statusCode int, errorMsg string) { | ||
object := Error{ | ||
Error: errorMsg, | ||
StatusCode: statusCode, | ||
} | ||
output, err := json.Marshal(object) | ||
if err != nil { | ||
log.Println("error:", err) | ||
} | ||
w.Header().Set("Content-Type", "application/json") | ||
w.WriteHeader(statusCode) | ||
_, err = w.Write(output) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters