Skip to content

Commit d91b358

Browse files
committed
fix(errors): add a base ClaimError
1 parent c22d895 commit d91b358

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

src/joserfc/errors.py

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -191,43 +191,40 @@ def __init__(self, cek_size: int): # pragma: no cover
191191
# --- JWT related errors --- #
192192

193193

194-
class InvalidClaimError(JoseError):
195-
"""This error is designed for JWT. It raised when the claim contains
196-
invalid values or types."""
194+
class ClaimError(JoseError):
195+
"""This a base error for JWT claims validation."""
197196

198197
claim: str
199-
error = "invalid_claim"
198+
description = "Error claim: '{}'"
200199

201200
def __init__(self, claim: str):
202201
self.claim = claim
203-
description = f"Invalid claim: '{claim}'"
204-
super(InvalidClaimError, self).__init__(description=description)
202+
description = self.description.format(claim)
203+
super(ClaimError, self).__init__(description=description)
204+
205+
206+
class InvalidClaimError(ClaimError):
207+
"""This error is designed for JWT. It raised when the claim contains
208+
invalid values or types."""
209+
210+
error = "invalid_claim"
211+
description = "Invalid claim: '{}'"
205212

206213

207-
class MissingClaimError(JoseError):
214+
class MissingClaimError(ClaimError):
208215
"""This error is designed for JWT. It raised when the required
209216
claims are missing."""
210217

211-
claim: str
212218
error = "missing_claim"
213-
214-
def __init__(self, claim: str):
215-
self.claim = claim
216-
description = f"Missing claim: '{claim}'"
217-
super(MissingClaimError, self).__init__(description=description)
219+
description = "Missing claim: '{}'"
218220

219221

220-
class InsecureClaimError(JoseError):
222+
class InsecureClaimError(ClaimError):
221223
"""This error is designed for JWT. It raised when the claim
222224
contains sensitive information."""
223225

224-
claim: str
225226
error = "insecure_claim"
226-
227-
def __init__(self, claim: str):
228-
self.claim = claim
229-
description = f"Insecure claim '{claim}'"
230-
super(InsecureClaimError, self).__init__(description=description)
227+
description = "Insecure claim: '{}'"
231228

232229

233230
class ExpiredTokenError(JoseError):

0 commit comments

Comments
 (0)