LiteNode's logo

LiteNode

Docs GitHub logo
▶ Usage

Documentation

Error Handling

LiteNode introduces custom error handling functionality with the onError method, allowing developers to define custom error handling logic for their applications. Additionally, LiteNode provides a built-in handler for 404 Not Found errors with the notFound method, enhancing the framework's robustness and reliability.

onError

Signature:

onError(handler: RouteHandler): LiteNode

Defines a custom error handling function for internal server errors.

handler: The asynchronous custom error handling function. Returns: A reference to the LiteNode instance for method chaining.

Example:

// Define custom error handling for internal server errors
app.onError(async (err, req, res) => {
    // Set the response status code to 500 (Internal Server Error)
    res.writeHead(500)
    // Send a response indicating internal server error
    res.end("Internal Server Error")
})

notFound

Signature:

notFound(handler: RouteHandler): LiteNode

Defines a handler for 404 (Not Found) errors.

handler: The asynchronous route handler function for 404 errors. Returns: A reference to the LiteNode instance for method chaining.

Example:

// Define handling for 404 (Not Found) errors
app.notFound(async (req, res) => {
    // Set the response status code to 404 (Not Found)
    res.writeHead(404)
    // Send a response indicating route not found
    res.end("Route Not Found")
})

Content