Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ease rendering of error pages from handlers #134

Open
dvogel opened this issue Nov 22, 2024 · 0 comments
Open

Ease rendering of error pages from handlers #134

dvogel opened this issue Nov 22, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@dvogel
Copy link
Collaborator

dvogel commented Nov 22, 2024

One frustration I've found while using pushup follows this template:

^handler {
  if (someCondition) {
    w.WriteHeader(404)
    return nil
  }
}

<p>
  This is my normal content.
</p>

When sending the error status code, I'd like to provide error page content. However rendering that content requires falling back to a conventional go web framework approach. However part of why I chose pushup for a particular app is to void the duties of setting up a conventional web framework. The path of least resistance is to redirect to an error page. However that provides a pretty poor user experience. e.g. It is difficult to link to the page that provided the 404 when a user finds it unexpected.

I haven't checked the implementation to see how feasible this is, but within the pushup paradigm, I'd like to be able to communicate more to the outer pushup controller via a richer return value:

^handler {
  if (someCondition) {
    errorDetails := url.Values{}
    errorDetails.Set("MissingSubject", "user")
    errorDetails.Set("MissingId", "123")
    
    return PushupRestart{
      Overrides: http.Request{
        Path: "/path/to/error/page",
        Form: errorDetails,
      }
    }
  }
}

That would allow defining the behavior of an error page as a page, routeable and testable on it's own, but also without requiring a redirect. It would also tie the intended effect to the return value, so the user could no longer forget to return after indicating an error with w.WriteHeader(...).

These enhanced return values could redirects as well. Currently, calling http.Redirect(...) and then having to also explicitly return nil can be a bit error prone.

^handler {
  if (someCondition) {
    return PushupRedirect{
      Status: 303,
      Location: "https://google.com?q=Let+me+google+that+for+you"
    }
  }
}

If the return value of a handler is not a practical way to deliver this functionality, perhaps a library function could be provided that does something similar to the code routing and rendering functionality:

^handler {
  if (someCondition) {
    errorDetails := url.Values{}
    errorDetails.Set("MissingSubject", "user")
    errorDetails.Set("MissingId", "123")
    substitutePage("/path/to/error/page", Request{ Form: errorDetails })
    return nil
  }
}

This would retain the benefits of the prior suggestion while still requiring the user to remember to return nil.

@dvogel dvogel added the enhancement New feature or request label Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant