Skip to content

Commit

Permalink
Merge pull request #4 from Cellane/patch-3
Browse files Browse the repository at this point in the history
Fixed compilation error introduced in PR#1
  • Loading branch information
proggeramlug authored Jul 24, 2018
2 parents bd4cead + 5e31cf6 commit c8cd6bd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Sources/APIErrorMiddleware/APIErrorMiddleware.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ public final class APIErrorMiddleware: Middleware, Service, ServiceType {

/// Creates a service instance. Used by a `ServiceFactory`.
public static func makeService(for worker: Container) throws -> APIErrorMiddleware {
return APIErrorMiddleware(environment: worker.environment, specializations: [ModelNotFound()])
#if canImport(Fluent)
return APIErrorMiddleware(environment: worker.environment, specializations: [ModelNotFound()])
#else
return APIErrorMiddleware(environment: worker.environment, specializations: [])
#endif
}

/// Catch all errors thrown by the route handler or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public protocol ErrorCatchingSpecialization {

// MARK: - ErrorCatchingSpecialization implementations

#if canImport(Fluent)
import Fluent

/// Catches Fluent's `modelNotFound` error and returns a 404 status code.
public struct ModelNotFound: ErrorCatchingSpecialization {
public init() {}
Expand All @@ -55,3 +58,4 @@ public struct ModelNotFound: ErrorCatchingSpecialization {
return nil
}
}
#endif

0 comments on commit c8cd6bd

Please sign in to comment.