Skip to content

Commit

Permalink
Fix typo in name
Browse files Browse the repository at this point in the history
  • Loading branch information
0xTim committed Sep 8, 2021
1 parent a2b5fca commit f2f7f54
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 22 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ targets: [
To use the LeafErrorMiddleware with the default context passed to templates, register the middleware service in `configure.swift` to your `Application`'s middleware (make sure you `import LeafErrorMiddleware` at the top):

```swift
app.middleware.use(LeafErorrMiddlewareDefaultGenerator.build())
app.middleware.use(LeafErrorMiddlewareDefaultGenerator.build())
```

Make sure it appears before all other middleware to catch errors.
Expand All @@ -58,7 +58,7 @@ let leafMiddleware = LeafErrorMiddleware() { status, error, req -> EventLoopFutu
app.middleware.use(leafMiddleware)
```

The closure recevies three parameters:
The closure receives three parameters:

* `HTTPStatus` - the status code of the response returned.
* `Error` - the error caught to be handled.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import Vapor

@available(*, deprecated, renamed: "LeafErrorMiddlewareDefaultGenerator")
public enum LeafErorrMiddlewareDefaultGenerator {
static func generate(_ status: HTTPStatus, _ error: Error, _ req: Request) -> EventLoopFuture<DefaultContext> {
let reason: String?
if let abortError = error as? AbortError {
reason = abortError.reason
} else {
reason = nil
}
let context = DefaultContext(status: status.code.description, statusMessage: status.reasonPhrase, reason: reason)
return req.eventLoop.future(context )
}

public static func build() -> LeafErrorMiddleware<DefaultContext> {
LeafErrorMiddleware(contextGenerator: generate)
}
}

public enum LeafErrorMiddlewareDefaultGenerator {
static func generate(_ status: HTTPStatus, _ error: Error, _ req: Request) -> EventLoopFuture<DefaultContext> {
let reason: String?
if let abortError = error as? AbortError {
reason = abortError.reason
} else {
reason = nil
}
let context = DefaultContext(status: status.code.description, statusMessage: status.reasonPhrase, reason: reason)
return req.eventLoop.future(context )
}

public static func build() -> LeafErrorMiddleware<DefaultContext> {
LeafErrorMiddleware(contextGenerator: generate)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class DefaultLeafErrorMiddlewareTests: XCTestCase {

try routes(app)

app.middleware.use(LeafErorrMiddlewareDefaultGenerator.build())
app.middleware.use(LeafErrorMiddlewareDefaultGenerator.build())
}

override func tearDownWithError() throws {
Expand Down Expand Up @@ -180,7 +180,7 @@ class DefaultLeafErrorMiddlewareTests: XCTestCase {
app.views.use { _ in
return self.viewRenderer
}
let middlewareGroup = app.grouped(LeafErorrMiddlewareDefaultGenerator.build())
let middlewareGroup = app.grouped(LeafErrorMiddlewareDefaultGenerator.build())
middlewareGroup.get("404") { req -> EventLoopFuture<Response> in
req.eventLoop.makeFailedFuture(Abort(.notFound))
}
Expand Down

0 comments on commit f2f7f54

Please sign in to comment.