@Test public void getErrorJson_JsonParsinException_validJson() throws IOException { ObjectMapper mockMapper = mock(ObjectMapper.class); JsonProcessingException exception = mock(JsonProcessingException.class); when(mockMapper.writeValueAsString(any(Object.class))).thenThrow(exception); String output = exceptionHandler.getErrorJson(INVALID_RESPONSE_MESSAGE); assertNotNull(output); ErrorModel error = objectMapper.readValue(output, ErrorModel.class); assertNotNull(error); assertEquals(INVALID_RESPONSE_MESSAGE, error.getMessage()); }
String getErrorJson(String message) { try { return LambdaContainerHandler.getObjectMapper().writeValueAsString(new ErrorModel(message)); } catch (JsonProcessingException e) { log.error("Could not produce error JSON", e); return "{ \"message\": \"" + message + "\" }"; } }
AwsProxyExceptionHandler implements ExceptionHandler<AwsProxyResponse> { String getErrorJson(String message) { try { return LambdaContainerHandler.getObjectMapper().writeValueAsString(new ErrorModel(message)); } catch (JsonProcessingException e) { log.error("Could not produce error JSON", e); return "{ \"message\": \"" + message + "\" }"; } } }
AwsProxyExceptionHandler implements ExceptionHandler<AwsProxyResponse> { String getErrorJson(String message) { try { return LambdaContainerHandler.getObjectMapper().writeValueAsString(new ErrorModel(message)); } catch (JsonProcessingException e) { log.error("Could not produce error JSON", e); return "{ \"message\": \"" + message + "\" }"; } }  }
AwsProxyExceptionHandler implements ExceptionHandler<AwsProxyResponse> { String getErrorJson(String message) { try { return LambdaContainerHandler.getObjectMapper().writeValueAsString(new ErrorModel(message)); } catch (JsonProcessingException e) { log.error("Could not produce error JSON", e); return "{ \"message\": \"" + message + "\" }"; } }  @Override AwsProxyResponse handle(Throwable ex); @Override void handle(Throwable ex, OutputStream stream); }
AwsProxyExceptionHandler implements ExceptionHandler<AwsProxyResponse> { String getErrorJson(String message) { try { return LambdaContainerHandler.getObjectMapper().writeValueAsString(new ErrorModel(message)); } catch (JsonProcessingException e) { log.error("Could not produce error JSON", e); return "{ \"message\": \"" + message + "\" }"; } }  @Override AwsProxyResponse handle(Throwable ex); @Override void handle(Throwable ex, OutputStream stream);  }