added error and not-implemented pages and placeholder ad graphic
This commit is contained in:
+37
-13
@@ -16,6 +16,39 @@ import (
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
func sendPageData(ctxt echo.Context, amctxt AmContext, command string, data any) error {
|
||||
var err error
|
||||
switch command {
|
||||
case "bytes":
|
||||
err = ctxt.Blob(amctxt.RC(), amctxt.OutputType(), data.([]byte))
|
||||
case "string":
|
||||
err = ctxt.String(amctxt.RC(), fmt.Sprintf("%v", data))
|
||||
case "template":
|
||||
err = amctxt.Render(fmt.Sprintf("%v", data))
|
||||
case "framed_template":
|
||||
amctxt.VarMap().Set("amsterdam_innerPage", data)
|
||||
err = amctxt.Render("frame.jet")
|
||||
default:
|
||||
err = fmt.Errorf("unknown rendering type: %s", command)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
/* ErrorPage renders the Amsterdam page with a server error message.
|
||||
* Parameters:
|
||||
* ctxt - The AmContext for the request.
|
||||
* input_err - The error to be rendered on the page.
|
||||
* Returns:
|
||||
* Command string dictating what to be rendered.
|
||||
* Data as a parameter for the command string.
|
||||
* Standard Go error status.
|
||||
*/
|
||||
func ErrorPage(ctxt AmContext, input_err error) (string, any, error) {
|
||||
ctxt.VarMap().Set("amsterdam_pageTitle", "Internal Server Error")
|
||||
ctxt.VarMap().Set("error", input_err.Error())
|
||||
return "framed_template", "error.jet", nil
|
||||
}
|
||||
|
||||
/* AmWrap wraps the Amsterdam handler function in a wrapper that implements the spec for
|
||||
* Echo handler functions.
|
||||
* Parameters:
|
||||
@@ -36,24 +69,15 @@ func AmWrap(myfunc func(AmContext) (string, any, error)) echo.HandlerFunc {
|
||||
ctxt.Logger().Errorf("Session save error: %v", err)
|
||||
return err
|
||||
}
|
||||
switch what {
|
||||
case "bytes":
|
||||
err = ctxt.Blob(amctxt.RC(), amctxt.OutputType(), rc.([]byte))
|
||||
case "string":
|
||||
err = ctxt.String(amctxt.RC(), fmt.Sprintf("%v", rc))
|
||||
case "template":
|
||||
err = amctxt.Render(fmt.Sprintf("%v", rc))
|
||||
case "framed_template":
|
||||
amctxt.VarMap().Set("amsterdam_innerPage", rc)
|
||||
err = amctxt.Render("frame.jet")
|
||||
default:
|
||||
err = fmt.Errorf("unknown rendering type: %s", what)
|
||||
}
|
||||
err = sendPageData(ctxt, amctxt, what, rc)
|
||||
if err != nil {
|
||||
ctxt.Logger().Errorf("Rendering error: %v", err)
|
||||
}
|
||||
} else {
|
||||
ctxt.Logger().Errorf("Page function error: %v", err)
|
||||
_, rc, _ = ErrorPage(amctxt, err)
|
||||
newerr := sendPageData(ctxt, amctxt, "framed_template", rc)
|
||||
err = newerr
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user