@architect/docs
Advanced tools
Comparing version 30.1.38 to 30.1.39
@@ -10,4 +10,2 @@ # HTTP | ||
> Coming soon: `text/css` and `text/javscript` | ||
## Request | ||
@@ -115,2 +113,40 @@ | ||
## Errors | ||
A `res` may also be invoked with an instance of `Error`. | ||
```javascript | ||
var arc = require('@architect/functions') | ||
// something went wrong! | ||
function fail(req, res) { | ||
res(Error('internal "server" error')) | ||
} | ||
exports.handler = arc.html.get(fail) | ||
``` | ||
By default an `Error` returns with an HTTP status code `500`. If the `Error` passed to `res` contains a property of `code`, `status` or `statusCode` with a value of `403`, `404` or `500` the status code response is updated accordingly. | ||
### Custom Error Page | ||
The default error response template can be overridden by adding `error.js` that exports a single default function that accepts an `Error` and returns a non empty `String`. | ||
```javascript | ||
// src/html/get-index/error.js | ||
module.exports = function error(err) { | ||
return ` | ||
<!doctype html> | ||
<html> | ||
<body> | ||
<h1>${err.message}</h1> | ||
<pre>${err.stack}</pre> | ||
</body> | ||
</html> | ||
` | ||
} | ||
``` | ||
> Have a look at the [error examples repo](https://github.com/arc-repos/arc-example-errors) and demos at https://wut0.click | ||
## Sessions | ||
@@ -117,0 +153,0 @@ |
{ | ||
"name": "@architect/docs", | ||
"version": "30.1.38", | ||
"version": "30.1.39", | ||
"main": "index", | ||
@@ -5,0 +5,0 @@ "scripts": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
134746