in online_formatter/src/main/kotlin/main.kt [34:51]
override fun handleRequest(event: APIGatewayProxyRequestEvent, context: Context?): String {
return gson.toJson(
try {
val request = gson.fromJson(event.body, Request::class.java)
val parsingErrors = ByteArrayOutputStream()
val style = request.style
val parsedArgs =
ParsedArgs.parseOptions(
PrintStream(parsingErrors), if (style == null) arrayOf() else arrayOf(style))
Response(
Formatter.format(
parsedArgs.formattingOptions.copy(maxWidth = request.maxWidth ?: 100),
request.source ?: ""),
parsingErrors.toString().ifEmpty { null })
} catch (e: Exception) {
Response(null, e.message)
})
}