Skip to content

Errors

Nubo has default server error handling and supports a custom error.nubo file.

If a route is missing, Nubo returns 404 Not Found.

If a request fails during parsing or interpretation, Nubo returns 500 Internal Server Error.

When serving a directory, Nubo checks for error.nubo in the server root.

app/
index.nubo
error.nubo

If error.nubo exists, Nubo runs it when an error happens.

Inside error.nubo, Nubo provides:

ModuleDescription
@server/requestCurrent request.
@server/responseResponse writer.
@server/errorError status and message.

The @server/error module contains:

FieldTypeDescription
statusintHTTP status code.
messagestringError message.

Example error.nubo:

import request from "@server/request"
import response from "@server/response"
import err from "@server/error"
response.status(err.status)
response.header("Content-Type", "text/html")
response.write(<ghost>
<h1>Error { err.status }</h1>
<p>{ err.message }</p>
<small>{ request.path }</small>
</ghost>)

If a Nubo runtime exception happens and the request prefers JSON, Nubo can return a JSON exception response.

The request prefers JSON when the Accept header contains:

application/json

For Nubo runtime exceptions, the server can return an HTML error page.

This is useful during development because exception pages can show structured runtime error information.