aboutsummaryrefslogtreecommitdiff
path: root/cmd/http/errors.go
diff options
context:
space:
mode:
authorAlex Scerba <alex@scerba.org>2024-09-27 18:56:29 -0400
committerAlex Scerba <alex@scerba.org>2024-09-27 18:56:29 -0400
commit2782bafcfdb69ef7b69a51a717a6bd35095e9369 (patch)
tree32d69f68fe2dbc6b9cc5a5ac8ff970d79f348156 /cmd/http/errors.go
parent1208c2e7e7e79cfe122f8d5f38160a0611cc9dfe (diff)
Add base files
Diffstat (limited to 'cmd/http/errors.go')
-rw-r--r--cmd/http/errors.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/cmd/http/errors.go b/cmd/http/errors.go
new file mode 100644
index 0000000..9406a9a
--- /dev/null
+++ b/cmd/http/errors.go
@@ -0,0 +1,23 @@
+package main
+
+import (
+ "fmt"
+ "net/http"
+ "runtime/debug"
+)
+
+func (app *application) serverError(w http.ResponseWriter, err error) {
+ trace := fmt.Sprintf("%s\n%s", err.Error(), debug.Stack())
+ app.errorLog.Output(2, trace)
+
+ http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
+}
+
+func (app *application) clientError(w http.ResponseWriter, status int) {
+ app.errorLog.Printf("Clent error: %d\n", status)
+ http.Error(w, http.StatusText(status), status)
+}
+
+func (app *application) notFound(w http.ResponseWriter) {
+ app.clientError(w, http.StatusNotFound)
+}