> On Sept. 21, 2022, 4:38 p.m., Madhan Neethiraj wrote: > > The patch looks good. One suggestion: instead of multiple exception mappers > > (GenericRangerJsonMappingExceptionMapper and > > GenericRangerJsonParserExceptionMapper), how about using a single mapper - > > similar to > > https://github.com/apache/ranger/blob/master/kms/src/main/java/org/apache/hadoop/crypto/key/kms/server/KMSExceptionsProvider.java? > > Ramachandran Krishnan wrote: > KMSExceptionsProvider looks very generic.But we need to handle only > invalid jsonformat,invalid attribute in valid json body.Inside generic > exception anyway we need to cast the generic exception into > JsonParseException or JsonMappingException ,etc.To make it clean i created > mapper for specific exception which we are looking into it. > > Madhan Neethiraj wrote: > Within a generic mapper, it is still possible to handle specific > exceptions like JsonParseException/JsonMappingException - similar to > KMSExceptionsProvider. It will help keep all exception handling in one place. > > Ramachandran Krishnan wrote: > Sure .We will do it .I will make necessary changes for this .
Added a generic Exception mapper .This class can be leveraged if we want to add any specific exception also in the future . - Ramachandran ----------------------------------------------------------- This is an automatically generated e-mail. To reply, visit: https://reviews.apache.org/r/74135/#review224695 ----------------------------------------------------------- On Sept. 22, 2022, 4:45 a.m., Ramachandran Krishnan wrote: > > ----------------------------------------------------------- > This is an automatically generated e-mail. To reply, visit: > https://reviews.apache.org/r/74135/ > ----------------------------------------------------------- > > (Updated Sept. 22, 2022, 4:45 a.m.) > > > Review request for ranger, Abhay Kulkarni, Madhan Neethiraj, Nikhil P, > Pradeep Agrawal, Ramesh Mani, Selvamohan Neethiraj, Sailaja Polavarapu, and > Velmurugan Periasamy. > > > Bugs: RANGER-3847 > https://issues.apache.org/jira/browse/RANGER-3847 > > > Repository: ranger > > > Description > ------- > > In Ranger rest API if you pass an Invalid attribute type in the JSON request > body, it throws a 404 error instead of 400 (Bad Request). It seems a bug > where we need to handle the JsonMappingException by adding Exception Mapper > globally to handle incorrect JSON format or Invalid attribute type in the > JSON request body otherwise our Rest API will throw a 404 error instead of > 400 error > > > Diffs > ----- > > > security-admin/src/main/java/org/apache/ranger/common/RangerExceptionProvider.java > PRE-CREATION > > > Diff: https://reviews.apache.org/r/74135/diff/2/ > > > Testing > ------- > > Request with proper request : Passing int values > > curl --location --request POST > 'https://----------------/service/xaudit/trx_log' \ > --header 'Authorization: Basic XXXX=' \ > --header 'Accept: application/json' \ > --header 'Content-Type: application/json' \ > --data-raw '{ > "objectClassType" : "123456", > "objectId" : "1234567" > }' > > Response : ok > > > Request with bad request : Passing String values > > curl --location --request POST 'https://---------/service/xaudit/trx_log' \ > --header 'Authorization: Basic XXXXX==' \ > --header 'Accept: application/json' \ > --header 'Content-Type: application/json' \ > --data-raw '{ > "objectClassType" : "abcdef", > "objectId" : "abcdef" > }' > > Response : > { > "errorCode": "Bad Request", > "error": "Can not construct instance of int from String value 'abcdef': not > a valid Integer value\n at [Source: > org.apache.catalina.connector.CoyoteInputStream@2c444edc; line: 1, column: 2] > (through reference chain: > org.apache.ranger.view.VXTrxLog[\"objectClassType\"])" > } > > > Thanks, > > Ramachandran Krishnan > >