mirror of
https://github.com/enso-org/enso.git
synced 2024-09-11 13:15:52 +03:00
Fix Error Payload Serialization (#3315)
This commit is contained in:
parent
d3cc2c1025
commit
d3846578cc
@ -4824,7 +4824,7 @@ Signals that the requested file read was out of bounds for the file's size.
|
|||||||
"error" : {
|
"error" : {
|
||||||
"code" : 1009
|
"code" : 1009
|
||||||
"message" : "Read is out of bounds for the file"
|
"message" : "Read is out of bounds for the file"
|
||||||
"data" : {
|
"payload" : {
|
||||||
"fileLength" : 0
|
"fileLength" : 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4927,7 +4927,7 @@ cannot be evaluated. The error contains an optional `data` field of type
|
|||||||
"error" : {
|
"error" : {
|
||||||
"code" : 2007,
|
"code" : 2007,
|
||||||
"message" : "Evaluation of the visualisation expression failed [i is not defined]"
|
"message" : "Evaluation of the visualisation expression failed [i is not defined]"
|
||||||
"data" : {
|
"payload" : {
|
||||||
"kind" : "Error",
|
"kind" : "Error",
|
||||||
"message" : "i is not defined",
|
"message" : "i is not defined",
|
||||||
"path" : null,
|
"path" : null,
|
||||||
|
@ -934,7 +934,7 @@ version that is required to complete the related action.
|
|||||||
"error" : {
|
"error" : {
|
||||||
"code" : 4022,
|
"code" : 4022,
|
||||||
"message" : "Project manager 1.2.3 is required to install the requested engine. Please upgrade.",
|
"message" : "Project manager 1.2.3 is required to install the requested engine. Please upgrade.",
|
||||||
"data": {
|
"payload": {
|
||||||
"minimumRequiredVersion": "1.2.3"
|
"minimumRequiredVersion": "1.2.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -188,7 +188,7 @@ class VisualisationOperationsTest extends BaseServerTest {
|
|||||||
"error" : {
|
"error" : {
|
||||||
"code" : 2007,
|
"code" : 2007,
|
||||||
"message" : $errorMessage,
|
"message" : $errorMessage,
|
||||||
"data": {
|
"payload": {
|
||||||
"kind" : "Error",
|
"kind" : "Error",
|
||||||
"message" : $expressionFailureMessage,
|
"message" : $expressionFailureMessage,
|
||||||
"path" : null,
|
"path" : null,
|
||||||
|
@ -31,7 +31,7 @@ object JsonProtocol {
|
|||||||
case class ResponseError(id: Option[Id], error: ErrorData) extends JsonMessage
|
case class ResponseError(id: Option[Id], error: ErrorData) extends JsonMessage
|
||||||
|
|
||||||
/** The error response details. */
|
/** The error response details. */
|
||||||
case class ErrorData(code: Int, message: String, data: Option[Json])
|
case class ErrorData(code: Int, message: String, payload: Option[Json])
|
||||||
|
|
||||||
object Constants {
|
object Constants {
|
||||||
val jsonrpc: String = "jsonrpc"
|
val jsonrpc: String = "jsonrpc"
|
||||||
@ -44,7 +44,7 @@ object JsonProtocol {
|
|||||||
val error: String = "error"
|
val error: String = "error"
|
||||||
val code: String = "code"
|
val code: String = "code"
|
||||||
val message: String = "message"
|
val message: String = "message"
|
||||||
val data: String = "data"
|
val payload: String = "payload"
|
||||||
}
|
}
|
||||||
|
|
||||||
implicit val notificationEncoder: Encoder[Notification] =
|
implicit val notificationEncoder: Encoder[Notification] =
|
||||||
@ -84,9 +84,9 @@ object JsonProtocol {
|
|||||||
Constants.code -> errorData.code.asJson,
|
Constants.code -> errorData.code.asJson,
|
||||||
Constants.message -> errorData.message.asJson
|
Constants.message -> errorData.message.asJson
|
||||||
)
|
)
|
||||||
val result = errorData.data match {
|
val result = errorData.payload match {
|
||||||
case Some(additionalPayload) =>
|
case Some(additionalPayload) =>
|
||||||
base.+:(Constants.data -> additionalPayload)
|
base.+:(Constants.payload -> additionalPayload)
|
||||||
case None =>
|
case None =>
|
||||||
base
|
base
|
||||||
}
|
}
|
||||||
|
@ -142,7 +142,11 @@ class MessageHandler(val protocol: Protocol, val controller: ActorRef)
|
|||||||
.resolveError(bareError.code)
|
.resolveError(bareError.code)
|
||||||
.getOrElse(
|
.getOrElse(
|
||||||
Errors
|
Errors
|
||||||
.UnknownError(bareError.code, bareError.message, bareError.data)
|
.UnknownError(
|
||||||
|
bareError.code,
|
||||||
|
bareError.message,
|
||||||
|
bareError.payload
|
||||||
|
)
|
||||||
)
|
)
|
||||||
controller ! ResponseError(mayId, error)
|
controller ! ResponseError(mayId, error)
|
||||||
mayId.foreach(id =>
|
mayId.foreach(id =>
|
||||||
@ -154,7 +158,7 @@ class MessageHandler(val protocol: Protocol, val controller: ActorRef)
|
|||||||
|
|
||||||
private def makeError(id: Option[Id], error: Error): String = {
|
private def makeError(id: Option[Id], error: Error): String = {
|
||||||
val bareError =
|
val bareError =
|
||||||
JsonProtocol.ErrorData(error.code, error.message, data = error.payload)
|
JsonProtocol.ErrorData(error.code, error.message, error.payload)
|
||||||
val bareErrorResponse = JsonProtocol.ResponseError(id, bareError)
|
val bareErrorResponse = JsonProtocol.ResponseError(id, bareError)
|
||||||
JsonProtocol.encode(bareErrorResponse)
|
JsonProtocol.encode(bareErrorResponse)
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ class ProjectCreateDefaultToLatestSpec
|
|||||||
"error": {
|
"error": {
|
||||||
"code": 4022,
|
"code": 4022,
|
||||||
"message": $message,
|
"message": $message,
|
||||||
"data" : {
|
"payload" : {
|
||||||
"minimumRequiredVersion" : "9999.0.0"
|
"minimumRequiredVersion" : "9999.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user