Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

resolve #58 return error response #72

Merged
merged 9 commits into from
Jun 24, 2019
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ import org.elasticsearch.script.ScriptException
import java.time.Instant

data class MonitorRunResult(
val monitorName: String,
val periodStart: Instant,
val periodEnd: Instant,
val error: Exception? = null,
val inputResults: InputRunResults = InputRunResults(),
val triggerResults: Map<String, TriggerRunResult> = mapOf()
val monitorName: String,
seraphjiang marked this conversation as resolved.
Show resolved Hide resolved
val periodStart: Instant,
val periodEnd: Instant,
val error: Exception? = null,
val inputResults: InputRunResults = InputRunResults(),
val triggerResults: Map<String, TriggerRunResult> = mapOf()
) : ToXContent {
override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder {
return builder.startObject()
Expand Down Expand Up @@ -71,16 +71,20 @@ data class InputRunResults(val results: List<Map<String, Any>> = listOf(), val e
}

data class TriggerRunResult(
val triggerName: String,
val triggered: Boolean,
val error: Exception? = null,
val actionResults: MutableMap<String, ActionRunResult> = mutableMapOf()
val triggerName: String,
val triggered: Boolean,
val error: Exception? = null,
val actionResults: MutableMap<String, ActionRunResult> = mutableMapOf()
) : ToXContent {
override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder {
var msg = error?.message
if (error is ScriptException) {
seraphjiang marked this conversation as resolved.
Show resolved Hide resolved
msg = error.toJsonString()
}
return builder.startObject()
.field("name", triggerName)
.field("triggered", triggered)
.field("error", error?.message)
.field("error", msg)
.field("action_results", actionResults as Map<String, ActionRunResult>)
.endObject()
}
Expand All @@ -100,12 +104,12 @@ data class TriggerRunResult(
}

data class ActionRunResult(
val actionId: String,
val actionName: String,
val output: Map<String, String>,
val throttled: Boolean = false,
val executionTime: Instant? = null,
val error: Exception? = null
val actionId: String,
val actionName: String,
val output: Map<String, String>,
val throttled: Boolean = false,
val executionTime: Instant? = null,
val error: Exception? = null
) : ToXContent {

override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder {
Expand Down