Skip to content

Commit e7b5111

Browse files
wcrestfieldAndrew-Lees11
authored andcommitted
feat: Enabling pattern matching on JWTErrors (#45)
1 parent a3fecfb commit e7b5111

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Sources/SwiftJWT/JWTError.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,12 @@ public struct JWTError: Error, Equatable {
5252
public static func == (lhs: JWTError, rhs: JWTError) -> Bool {
5353
return lhs.internalError == rhs.internalError
5454
}
55+
56+
/// Function to enable pattern matching against generic Errors.
57+
public static func ~= (lhs: JWTError, rhs: Error) -> Bool {
58+
guard let rhs = rhs as? JWTError else {
59+
return false
60+
}
61+
return lhs == rhs
62+
}
5563
}

0 commit comments

Comments
 (0)