From c391be9e4de9f3d2751aa88881e30bd42c5d373c Mon Sep 17 00:00:00 2001 From: mikestefanello Date: Sat, 1 Jan 2022 13:44:09 -0500 Subject: [PATCH] Added route errors to README. --- README.md | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bdc5296..e10875d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,10 @@ ## Pagoda: Rapid, easy full-stack web development starter kit in Go +[![Go Report Card](https://goreportcard.com/badge/github.com/mikestefanello/pagoda)](https://goreportcard.com/report/github.com/mikestefanello/pagoda) +[![Test](https://github.com/mikestefanello/pagoda/actions/workflows/test.yml/badge.svg)](https://github.com/mikestefanello/pagoda/actions/workflows/test.yml) +[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) +[![GoT](https://img.shields.io/badge/Made%20with-Go-1f425f.svg)](https://go.dev) +

Logo

## Table of Contents @@ -38,7 +43,7 @@ * [Custom middleware](#custom-middleware) * [Controller / Dependencies](#controller--dependencies) * [Patterns](#patterns) - * [Custom middleware](#custom-middleware) + * [Errors](#errors) * [Testing](#testing) * [HTTP server](#http-server) * [Request / Request helpers](#request--response-helpers) @@ -381,6 +386,12 @@ Your route will now have all methods available on the `Controller` as well as ac **It is highly recommended** that you provide a `Name` for your routes. Most methods on the back and frontend leverage the route name and parameters in order to generate URLs. +### Errors + +Routes can return errors to indicate that something wrong happened. Ideally, the error is of type `*echo.HTTPError` to indicate the intended HTTP response code. You can use `return echo.NewHTTPError(http.StatusInternalServerError)`, for example. If an error of a different type is returned, an _Internal Server Error_ is assumed. + +The [error handler](https://echo.labstack.com/guide/error-handling/) is set to a provided route `routes/error.go` in the `BuildRouter()` function. That means that if any middleware or route return an error, the request gets routed there. This route conveniently constructs and renders a `Page` which uses the template `templates/pages/error.go`. The status code is passed to the template so you can easily alter the markup depending on the error type. + ### Testing Since most of your web application logic will live in your routes, being able to easily test them is important. The following aims to help facilitate that. @@ -906,7 +917,7 @@ Future work includes but is not limited to: - Email verification - Flexible pager templates -- Expanded HTMX examples +- Expanded HTMX examples and integration - Admin section ## Credits