initial commits

master
Charles Iliya Krempeaux 2023-08-14 21:53:51 -07:00
parent ae7875d8e5
commit 9c0263cfa4
1 changed files with 60 additions and 0 deletions

60
serveerror.go 100644
View File

@ -0,0 +1,60 @@
package maymoon
import (
"sourcecode.social/reiver/go-errhttp"
"fmt"
"net/http"
)
func serveError(responsewriter http.ResponseWriter, err error) {
if nil == responsewriter {
/////////////// RETURN
return
}
if nil == err {
http.Error(responsewriter, "Internal Server Error\n\nMissing Error\n", http.StatusInternalServerError)
/////////////// RETURN
return
}
var e errhttp.Error
{
var casted bool
e, casted = err.(errhttp.Error)
if !casted {
var msg []byte = []byte("Internal Server Error\n\n")
msg = append(msg, err.Error()...)
msg = append(msg, '\n')
http.Error(responsewriter, string(msg), http.StatusInternalServerError)
/////////////////////// RETURN
return
}
}
var statuscode int = e.ErrHTTP()
var msg []byte
{
var statustext string = http.StatusText(statuscode)
if "" == statustext {
statustext = fmt.Sprintf("HTTP Error %d", statuscode)
}
msg = append(msg, statustext...)
}
{
var inner error = e.Unwrap()
if nil != inner {
msg = append(msg, "\n\n"...)
msg = append(msg, inner.Error()...)
msg = append(msg, '\n')
}
}
http.Error(responsewriter, string(msg), statuscode)
}