Until AWS comes to the party and fixes this one my only workaround is to catch thrown exceptions in the Lambda handler and throw a wrapping exception with the same message but with '\n' characters replaced by "\n". This is an imperfect solution because currently the non-proxy integration error handling does something odd with that character sequence and I end up with two backslashes and an n in the json instead of one backslash and n (which is how you specify a newline character in json).
One interesting thing about the this integration problem I notice is that the cause
part of the exception (which is mapped to a json block for the causing exception) does have correct handling of newline characters (!). This means that wrapping the exception with an exception with a simple message or no message will pass the original exception message correctly formatted into the cause
field of the json.
Here's an example of json returned from a non-proxy api lambda integration that uses the approach I discussed. You can see the extra backslashes in the errorMessage field and you can see correctly formatted newline characters in the cause errorMessage field.
{
"errorMessage":"ServerException: Error occurred at position, start= 40, finish=81 with desc='aircraftRegistrationMarking', value='VH OSA?':\\nWARNING - SUSPECT NON-SPEC IN AIRCRAFT REG. MARKING\\n?1 = 100100 = Space - Right Justified\\n",
"errorType":"com.github.davidmoten.aws.helper.ServerException",
"stackTrace":[
"au.gov.amsa.beacon.decoder.Handler.handleRequest(Handler.java:76)",
"sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)",
"sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)",
"sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)",
"java.lang.reflect.Method.invoke(Method.java:498)"
],
"cause":{
"errorMessage":"Error occurred at position, start= 40, finish=81 with desc='aircraftRegistrationMarking', value='VH OSA?':\nWARNING - SUSPECT NON-SPEC IN AIRCRAFT REG. MARKING\n?1 = 100100 = Space - Right Justified\n",
"errorType":"java.lang.RuntimeException",
"stackTrace":[
"au.gov.amsa.fgb.internal.DecodeAsJson.getData(DecodeAsJson.java:28)",
"au.gov.amsa.fgb.internal.HexDecoder.decodeFullAsJson(HexDecoder.java:51)",
"au.gov.amsa.fgb.internal.Decoder.decodeFullAsJson(Decoder.java:11)",
"au.gov.amsa.fgb.Beacon15HexId.decodeHexToJson(Beacon15HexId.java:16)",
"au.gov.amsa.beacon.decoder.Handler.handleRequest(Handler.java:39)",
"sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)",
"sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)",
"sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)",
"java.lang.reflect.Method.invoke(Method.java:498)"
]
}
}
For your interest (and for the attention of AWS!) if I don't replace the new lines in the primary exception message this is what I get (invalid JSON, missing lots of double quote characters):
{errorMessage=ServerException: Error occurred at position, start= 40, finish=81 with desc='aircraftRegistrationMarking', value='VH OSA?':
WARNING - SUSPECT NON-SPEC IN AIRCRAFT REG. MARKING
?1 = 100100 = Space - Right Justified
, errorType=com.github.davidmoten.aws.helper.ServerException, stackTrace=["au.gov.amsa.beacon.decoder.Handler.handleRequest(Handler.java:75)","sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)","sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)","sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)","java.lang.reflect.Method.invoke(Method.java:498)"], cause={errorMessage=Error occurred at position, start= 40, finish=81 with desc='aircraftRegistrationMarking', value='VH OSA?':
WARNING - SUSPECT NON-SPEC IN AIRCRAFT REG. MARKING
?1 = 100100 = Space - Right Justified
, errorType=java.lang.RuntimeException, stackTrace=["au.gov.amsa.fgb.internal.DecodeAsJson.getData(DecodeAsJson.java:28)","au.gov.amsa.fgb.internal.HexDecoder.decodeFullAsJson(HexDecoder.java:51)","au.gov.amsa.fgb.internal.Decoder.decodeFullAsJson(Decoder.java:11)","au.gov.amsa.fgb.Beacon15HexId.decodeHexToJson(Beacon15HexId.java:16)","au.gov.amsa.beacon.decoder.Handler.handleRequest(Handler.java:38)","sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)","sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)","sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)","java.lang.reflect.Method.invoke(Method.java:498)"]}}