Skip to content

Commit 14f95e0

Browse files
authored
Merge pull request #1 from Cellane/patch-1
Fixed ModelNotFound specialization
2 parents 2025900 + 3f71ef8 commit 14f95e0

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

Sources/APIErrorMiddleware/Specialization/Specialization.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ public protocol ErrorCatchingSpecialization {
4343
/// Catches Fluent's `modelNotFound` error and returns a 404 status code.
4444
public struct ModelNotFound: ErrorCatchingSpecialization {
4545
public init() {}
46-
46+
4747
public func convert(error: Error, on request: Request) -> ErrorResult? {
48-
if let error = error as? Debuggable, error.identifier == "modelNotFound" {
49-
50-
// We have the infamous `modelNotFound` error from Fluent that returns
51-
// a 500 status code instead of a 404.
52-
// Set the message to the error's `reason` and the status to 404 (Not Found)
48+
if
49+
let wrappingError = error as? NotFound,
50+
let error = wrappingError.rootCause as? FluentError
51+
{
5352
return ErrorResult(message: error.reason, status: .notFound)
5453
}
54+
5555
return nil
5656
}
5757
}

0 commit comments

Comments
 (0)