@@ -92,7 +92,6 @@ public void setRestTemplate(RestTemplate restTemplate) {
9292 * the string in to JsonElement not using JsonElement directly here.
9393 *
9494 * <p>
95- * <p>
9695 * Parameters: msgProtocol - The message protocol, which tells us which
9796 * service to invoke. msgType - The type of message that needs to be
9897 * generated. body - The content of the message which is used in
@@ -127,7 +126,7 @@ public ResponseEntity<?> generate(@ApiParam(value = "message protocol", required
127126 lookupLimit , okToLeaveOutInvalidOptionalFields , inputJson );
128127 } catch (JsonSyntaxException | JsonProcessingException e ) {
129128 String exceptionMessage = e .getMessage ();
130- log .error ("Invalid JSON parse data format due to: " , e .getMessage ());
129+ log .error ("Invalid JSON parse data format due to" , e .getMessage ());
131130 return createResponseEntity (HttpStatus .BAD_REQUEST , "Invalid JSON parse data format due to: " + exceptionMessage , "fatal" ,
132131 errorResponse );
133132 }
@@ -137,8 +136,6 @@ public ResponseEntity<?> generate(@ApiParam(value = "message protocol", required
137136 * Returns event information as json element based on the message protocol,
138137 * taking message type and json body as input
139138 * Here we basically add this to handle if inputData is of jsonArray type as well
140- *
141- * <p>
142139 * <p>
143140 * Parameters: msgProtocol - The message protocol, which tells us which
144141 * service to invoke. msgType - The type of message that needs to be
@@ -158,7 +155,7 @@ public ResponseEntity<?> generate(final String msgProtocol, final String msgType
158155 return new ResponseEntity <>("Parameter 'lookupLimit' must be > 0" , HttpStatus .BAD_REQUEST );
159156 }
160157 if (inputData == null ) {
161- createResponseEntity (HttpStatus .BAD_REQUEST , JSON_ERROR_STATUS ,
158+ return createResponseEntity (HttpStatus .BAD_REQUEST , JSON_ERROR_STATUS ,
162159 "Parameter 'inputData' must not be null" , errorResponse );
163160 }
164161
@@ -182,7 +179,7 @@ public ResponseEntity<?> generate(final String msgProtocol, final String msgType
182179 JsonObject processedJson = processEvent (msgProtocol , msgType , failIfMultipleFound , failIfNoneFound ,
183180 lookupInExternalERs , lookupLimit , okToLeaveOutInvalidOptionalFields , inputJsonObject );
184181
185- HttpStatus status = null ;
182+ HttpStatus status = null ;
186183 if (processedJson .has (META )) {
187184 status = HttpStatus .OK ;
188185 return new ResponseEntity <>(processedJson , status );
@@ -199,7 +196,7 @@ public ResponseEntity<?> generate(final String msgProtocol, final String msgType
199196 "Invalid JSON format,expected either single template or array of templates" ,
200197 JSON_ERROR_STATUS , errorResponse );
201198 }
202- } catch (REMGenerateException | JsonSyntaxException e ) {
199+ } catch (REMGenerateException | JsonSyntaxException | NumberFormatException e ) {
203200 return handleException (e );
204201 }
205202 }
@@ -231,7 +228,6 @@ public void initializeResponse(HttpStatus status, String errorMessage, String re
231228 * @param e taken general exception here
232229 * @return ResponseEntity
233230 */
234-
235231 private ResponseEntity <JsonObject > handleException (Exception e ) {
236232 JsonObject errorResponse = new JsonObject ();
237233 String exceptionMessage = e .getMessage ();
@@ -245,10 +241,13 @@ private ResponseEntity<JsonObject> handleException(Exception e) {
245241 status , e .getMessage (), JSON_ERROR_STATUS , errorResponse );
246242 }
247243 }
248- return createResponseEntity (HttpStatus .BAD_REQUEST , e . getMessage () , JSON_ERROR_STATUS , errorResponse );
244+ return createResponseEntity (HttpStatus .BAD_REQUEST , exceptionMessage , JSON_ERROR_STATUS , errorResponse );
249245 } else if (e instanceof JsonSyntaxException ) {
250- log .error ("Failed to parse JSON: " , exceptionMessage );
251- return createResponseEntity (HttpStatus .BAD_REQUEST , e .getMessage (), JSON_ERROR_STATUS , errorResponse );
246+ log .error ("Failed to parse JSON" , exceptionMessage );
247+ return createResponseEntity (HttpStatus .BAD_REQUEST , exceptionMessage , JSON_ERROR_STATUS , errorResponse );
248+ } else if (e instanceof NumberFormatException ) {
249+ log .error ("Invalid number format" , exceptionMessage );
250+ return createResponseEntity (HttpStatus .BAD_REQUEST , exceptionMessage , JSON_ERROR_STATUS , errorResponse );
252251 } else {
253252 log .error ("Unexpected exception caught" , exceptionMessage );
254253 return createResponseEntity (HttpStatus .INTERNAL_SERVER_ERROR , exceptionMessage , JSON_ERROR_STATUS , errorResponse );
0 commit comments