Skip to content

Commit c8cd6bd

Browse files
authored
Merge pull request #4 from Cellane/patch-3
Fixed compilation error introduced in PR#1
2 parents bd4cead + 5e31cf6 commit c8cd6bd

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

Sources/APIErrorMiddleware/APIErrorMiddleware.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ public final class APIErrorMiddleware: Middleware, Service, ServiceType {
2424

2525
/// Creates a service instance. Used by a `ServiceFactory`.
2626
public static func makeService(for worker: Container) throws -> APIErrorMiddleware {
27-
return APIErrorMiddleware(environment: worker.environment, specializations: [ModelNotFound()])
27+
#if canImport(Fluent)
28+
return APIErrorMiddleware(environment: worker.environment, specializations: [ModelNotFound()])
29+
#else
30+
return APIErrorMiddleware(environment: worker.environment, specializations: [])
31+
#endif
2832
}
2933

3034
/// Catch all errors thrown by the route handler or

Sources/APIErrorMiddleware/Specialization/Specialization.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ public protocol ErrorCatchingSpecialization {
4040

4141
// MARK: - ErrorCatchingSpecialization implementations
4242

43+
#if canImport(Fluent)
44+
import Fluent
45+
4346
/// Catches Fluent's `modelNotFound` error and returns a 404 status code.
4447
public struct ModelNotFound: ErrorCatchingSpecialization {
4548
public init() {}
@@ -55,3 +58,4 @@ public struct ModelNotFound: ErrorCatchingSpecialization {
5558
return nil
5659
}
5760
}
61+
#endif

0 commit comments

Comments
 (0)