package Ġdev . q riv i . n unt ium . server . controller Ċ Ċ import Ġdev . q riv i . n unt ium . server . controller . dto . res . Response Ċ import Ġdev . q riv i . n unt ium . server . controller . dto . res . error . BadRequest Ċ import Ġdev . q riv i . n unt ium . server . controller . dto . res . error . InternalServerError Ċ import Ġdev . q riv i . n unt ium . server . controller . dto . res . error . Method Not Allowed Ċ import Ġdev . q riv i . n unt ium . server . controller . dto . res . error . NotFound Ċ import Ġdev . q riv i . n unt ium . server . controller . dto . res . error . Unauthorized Ċ import Ġdev . q riv i . n unt ium . server . service . Message Service Ċ import Ġdev . q riv i . n unt ium . server . util . generate Response Ċ import Ġio . json web token . Expired Jwt Exception Ċ import Ġio . json web token . Jwt Exception Ċ import Ġio . json web token . Malformed Jwt Exception Ċ import Ġio . json web token . Unsupported Jwt Exception Ċ import Ġio . json web token . security . Signature Exception Ċ import Ġorg . springframework . http . Response Entity Ċ import Ġorg . springframework . http . converter . Http Message Not Readable Exception Ċ import Ġorg . springframework . security . authentication . Authentication Credentials NotFoundException Ċ import Ġorg . springframework . web . HttpRequest Method NotSupportedException Ċ import Ġorg . springframework . web . bind . annotation . Controller Ad vice Ċ import Ġorg . springframework . web . bind . annotation . ExceptionHandler Ċ import Ġorg . springframework . web . servlet . No Handler Found Exception Ċ import Ġjavax . servlet . http . HttpServletRequest Ċ Ċ @ Controller Ad vice Ċ class ĠException Resolver ( private Ġval Ġmessages : ĠMessage Service ) Ġ{ ĊĊĠĠĠ Ġ@ ExceptionHandler ĊĠĠĠ Ġfun Ġhandle Http Message Not Readable Exception ( e : ĠHttp Message Not Readable Exception ): ĠResponseEntity < Response > Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġgenerate Response ( BadRequest ( error Ġ= Ġmessages [" n unt ium . exception . Http Message Not Readable Exception . message "])) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ ExceptionHandler ĊĠĠĠ Ġfun Ġhandle No Handler Found Exception ( e : ĠNo Handler Found Exception ): ĠResponseEntity < Response > Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġgenerate Response ( NotFound ( error Ġ= Ġmessages [" n unt ium . exception . No Handler Found Exception . message "])) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ ExceptionHandler ĊĠĠĠ Ġfun Ġhandle HttpRequest Method NotSupportedException ( e : ĠHttpRequest Method NotSupportedException ): ĠResponseEntity < Response > Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġgenerate Response ( Method Not Allowed ( error Ġ= Ġe . message !! )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ ExceptionHandler ĊĠĠĠ Ġfun Ġhandle Expired Jwt Exception ( e : ĠExp ired Jwt Exception , Ġreq : ĠHttpServletRequest ): ĠResponseEntity < Response > Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġgenerate Response ( Unauthorized ( reason Ġ= ĠUnauthorized . Reason . EXPI RED _ ACCESS _ TOKEN , Ġrealm Ġ= Ġreq . server Name )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ ExceptionHandler ĊĠĠĠ Ġfun Ġhandle Unsupported Jwt Exception ( e : ĠUnsupported Jwt Exception , Ġreq : ĠHttpServletRequest ): ĠResponseEntity < Response > Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġgenerate Response ( Unauthorized ( reason Ġ= ĠUnauthorized . Reason . INVALID _ ACCESS _ TOKEN , Ġrealm Ġ= Ġreq . server Name )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ ExceptionHandler ĊĠĠĠ Ġfun Ġhandle Malformed Jwt Exception ( e : ĠMal formed Jwt Exception , Ġreq : ĠHttpServletRequest ): ĠResponseEntity < Response > Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġgenerate Response ( Unauthorized ( reason Ġ= ĠUnauthorized . Reason . INVALID _ ACCESS _ TOKEN , Ġrealm Ġ= Ġreq . server Name )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ ExceptionHandler ĊĠĠĠ Ġfun Ġhandle Signature Exception ( e : ĠSignature Exception , Ġreq : ĠHttpServletRequest ): ĠResponseEntity < Response > Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġgenerate Response ( Unauthorized ( reason Ġ= ĠUnauthorized . Reason . INVALID _ ACCESS _ TOKEN , Ġrealm Ġ= Ġreq . server Name )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ ExceptionHandler ĊĠĠĠ Ġfun Ġhandle Jwt Exception ( e : ĠJwt Exception , Ġreq : ĠHttpServletRequest ): ĠResponseEntity < Response > Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġgenerate Response ( Unauthorized ( reason Ġ= ĠUnauthorized . Reason . NO _ TOKEN _ PROVIDED , Ġrealm Ġ= Ġreq . server Name )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ ExceptionHandler ĊĠĠĠ Ġfun Ġhandle Authentication Credentials NotFoundException ( e : ĠAuthentication Credentials NotFoundException , Ġreq : ĠHttpServletRequest ): ĠResponseEntity < Response > Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġgenerate Response ( Unauthorized ( reason Ġ= ĠUnauthorized . Reason . INVALID _ TOKEN _ ACCOUNT , Ġrealm Ġ= Ġreq . server Name )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ ExceptionHandler ĊĠĠĠ Ġfun Ġhandle Exception ( e : ĠException ): ĠResponseEntity < Response > Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġwho ops ies Ġ= Ġmutable ListOf ( messages [" n unt ium . exception . Exception . message "], Ġe . message Ġ?: Ġe . java Class . simple Name ) ĊĠĠĠĠĠĠĠ Ġvar Ġcause Ġ= Ġe . cause ĊĠĠĠĠĠĠĠ Ġvar Ġlimit Ġ= Ġ 1 0 ĊĠĠĠĠĠĠĠ Ġwhile Ġ( cause Ġ!= Ġnull Ġ&& Ġlimit Ġ!= Ġ 0 ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġwho ops ies . add ( cause . message Ġ?: Ġcause . java Class . simple Name ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcause Ġ= Ġcause . cause ĊĠĠĠĠĠĠĠĠĠĠĠ Ġlimit -- ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġreturn Ġgenerate Response ( InternalServerError ( errors Ġ= Ġwho ops ies . toList ())) ĊĠĠĠ Ġ} Ċ } Ċ