podium-lib / issues

All podium issues, bugs, questions etc goes here. Documentation is to be found at https://podium-lib.io
1 stars 0 forks source link

Enable podlet to set 3xx and 4xx status codes #29

Closed froderis closed 3 years ago

froderis commented 4 years ago

Some cases requires a podlet to send redirects or set the page status code. The current need is a CMS podlet that keeps track of changed urls and sends permanent redirect. Other use cases are triggering a login flow or setting 404 or 410 for cms or ad content.

digitalsadhu commented 4 years ago

Currently most of the cases listed are covered except the redirect case. Whenever throwable is triggered, a Boom error is created and the http status code is attached: https://github.com/podium-lib/client/blob/master/lib/resolver.content.js#L152-L159

podlet marked as throwable gets status code on error.output property

try {
  const result = podlet.fetch(incoming);
} catch (error) {
  // do something with error
  // error.output.statusCode === 404
  // send error to express error middleware with... 
  next(error)
}

All non 2xx responses will trigger the catch block and its then up to you how you want to handle.

The one case we don't have fully covered is the redirect case because we currently do not attach the location header to the error so while you can check that the status code is 3xx, you can't actually do anything about this. We will add this.

digitalsadhu commented 4 years ago

Working on this here: https://github.com/podium-lib/client/pull/104

digitalsadhu commented 3 years ago

Fixed in podium-lib/client#104