brokenhandsio / leaf-error-middleware Goto Github PK
View Code? Open in Web Editor NEWServe up custom 404 and server error pages for your Vapor App
License: MIT License
Serve up custom 404 and server error pages for your Vapor App
License: MIT License
You should update the version to 1.0.0-rc.1.0 in the readme because it's stuck at 0.10
I'd like to host both API and public web endpoints in a single app, but I don't want HTML error pages for my API endpoints.
I've tried the following, without registering against the default middlewares:
router.grouped(LeafErrorMiddleware.self)
But it doesn't work.
In Package.swift
:
dependencies: [
...,
.package(name: "LeafErrorMiddleware", url: "https://github.com/brokenhandsio/leaf-error-middleware.git", from: "2.0.0")
],
targets: [
.target(name: "App", dependencies: [
...,
"LeafErrorMiddleware"
]),
...,
]
but got
Showing Recent Messages
An unknown error occurred. '/Users/.../SourcePackages/checkouts/leaf-error-middleware' exists and is not an empty directory (-4)
Currently when doing throw Abort.redirect("/some-route")
is being redirected to serverError.leaf
, many of 3xx codes are not really errors.
This middleware should allow redirect errors to pass through, since sometimes it's just easier to abort.
Since all authentication redirect functionality has been removed from vapor (can't find it in vapor 3, but google shows it was there), imagine a helper function:
@discardableResult
func checkAuth(_ req: Request) throws -> User {
do {
return try req.requireAuthenticated(User.self)
}
catch {
throw Abort.redirect(to: "/login")
}
}
If it fails, serverError.leaf will be shown with 303 error instead of redirect.
I'm just wondering if it's possible to pass through a custom 404 error reason (say, "this article ID is not valid") instead of just a blank 404 error with no reason for it?
I feel this could be an enhancement since the boilerplate already exists for server errors.
LeafErorrMiddlewareDefaultGenerator should be LeafErrorMiddlewareDefaultGenerator - it’s a minor type in spelling of “error” but trips up in the setup. The configuration will not work otherwise. Can this be fixed. Thanks.
Are there any plans for Vapor 3 compatibility?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.