File tree Expand file tree Collapse file tree 1 file changed +6
-6
lines changed
Sources/APIErrorMiddleware/Specialization Expand file tree Collapse file tree 1 file changed +6
-6
lines changed Original file line number Diff line number Diff line change @@ -43,15 +43,15 @@ public protocol ErrorCatchingSpecialization {
43
43
/// Catches Fluent's `modelNotFound` error and returns a 404 status code.
44
44
public struct ModelNotFound : ErrorCatchingSpecialization {
45
45
public init ( ) { }
46
-
46
+
47
47
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
+ {
53
52
return ErrorResult ( message: error. reason, status: . notFound)
54
53
}
54
+
55
55
return nil
56
56
}
57
57
}
You can’t perform that action at this time.
0 commit comments