MNT-23927 Handle JsonMappingException and JsonGenerationException (#2289)

* Throw JSON exceptions as IO exceptions to be properly handled
* Log null prop keys
* Fix test to have the mocked response different than null
This commit is contained in:
Eva Vasques
2023-11-08 14:58:08 +00:00
committed by GitHub
parent 6065c6feec
commit a3ccafb035
3 changed files with 10 additions and 8 deletions

View File

@@ -104,13 +104,9 @@ public class JacksonHelper implements InitializingBean
JsonGenerator generator = objectMapper.getFactory().createGenerator(outStream, encoding);
writer.writeContents(generator, objectMapper);
}
catch (JsonMappingException error)
catch (JsonMappingException | JsonGenerationException error)
{
logger.error("Failed to write Json output", error);
}
catch (JsonGenerationException generror)
{
logger.error("Failed to write Json output", generror);
throw new IOException("Failed to write Json output", error);
}
}

View File

@@ -262,13 +262,15 @@ public class ExecutionTests extends AbstractContextTest implements ResponseWrite
{
AbstractResourceWebScript executor = getExecutor();
Map<String, String> templateVars = new HashMap();
WebScriptResponse response = mockResponse();
templateVars.put("apiScope", "private");
templateVars.put("apiVersion", "1");
templateVars.put("apiName", "alfrescomock");
templateVars.put(ResourceLocator.COLLECTION_RESOURCE, "sheep");
executor.execute(ApiAssistant.determineApi(templateVars), mockRequest(templateVars,new HashMap<String, List<String>>(1)), mock(WebScriptResponse.class));
executor.execute(ApiAssistant.determineApi(templateVars), mockRequest(templateVars,new HashMap<String, List<String>>(1)), response);
WebScriptResponse response = mockResponse();
response = mockResponse();
templateVars.put(ResourceLocator.COLLECTION_RESOURCE, "bad");
executor.execute(api, mockRequest(templateVars,new HashMap<String, List<String>>(1)), response);
//throws a runtime exception so INTERNAL_SERVER_ERROR