You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2020/08/14 09:07:31 UTC

[james-project] 03/13: JAMES-3349: Propose a refactor for simplify Invocation.error

This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 06930bdcfbbe2e04b0579d855edca5aa54a51eb4
Author: duc91 <vd...@linagora.com>
AuthorDate: Tue Aug 11 10:18:13 2020 +0700

    JAMES-3349: Propose a refactor for simplify Invocation.error
---
 .../org/apache/james/jmap/method/MailboxGetMethod.scala     |  2 +-
 .../main/scala/org/apache/james/jmap/model/Invocation.scala | 13 ++-----------
 .../scala/org/apache/james/jmap/routes/JMAPApiRoutes.scala  |  2 +-
 3 files changed, 4 insertions(+), 13 deletions(-)

diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxGetMethod.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxGetMethod.scala
index 91b0b46..ed582f4 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxGetMethod.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxGetMethod.scala
@@ -61,7 +61,7 @@ class MailboxGetMethod @Inject() (serializer: Serializer,
           mailboxGetRequest.properties match {
             case Some(properties) if !properties.asSetOfString.subsetOf(Mailbox.allProperties) =>
               SMono.just(Invocation.error(errorCode = ErrorCode.InvalidArguments,
-                description = Some(s"The following properties [${properties.asSetOfString.diff(Mailbox.allProperties).mkString(", ")}] do not exist."),
+                description = s"The following properties [${properties.asSetOfString.diff(Mailbox.allProperties).mkString(", ")}] do not exist.",
                 methodCallId = invocation.methodCallId))
             case _ => getMailboxes(capabilities, mailboxGetRequest, mailboxSession)
               .reduce(MailboxGetResults(Set.empty, NotFound(Set.empty)), (result1: MailboxGetResults, result2: MailboxGetResults) => result1.merge(result2))
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/model/Invocation.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/model/Invocation.scala
index 7e99723..7d80d0b 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/model/Invocation.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/model/Invocation.scala
@@ -35,9 +35,9 @@ object Invocation {
   case class MethodCallId(value: NonEmptyString)
 
 
-  def error(errorCode: ErrorCode, description: Option[String], methodCallId: MethodCallId): Invocation = {
+  def error(errorCode: ErrorCode, description: NonEmptyString, methodCallId: MethodCallId): Invocation = {
     Invocation(MethodName("error"),
-      Arguments(JsObject(Map("type" -> JsString(errorCode.code), "description" -> JsString(description.getOrElse(errorCode.defaultDescription))))),
+      Arguments(JsObject(Map("type" -> JsString(errorCode.code), "description" -> JsString(description)))),
       methodCallId)
   }
   def error(errorCode: ErrorCode, methodCallId: MethodCallId): Invocation = {
@@ -49,31 +49,22 @@ object Invocation {
 
 sealed trait ErrorCode {
   def code: String
-  def defaultDescription: String
 }
 
 object ErrorCode {
   case object InvalidArguments extends ErrorCode {
     override def code: String = "error"
-
-    override def defaultDescription: String = "One of the arguments is of the wrong type or otherwise invalid, or a required argument is missing."
   }
 
   case object ServerFail extends ErrorCode {
     override def code: String = "serverFail"
-
-    override def defaultDescription: String = null
   }
 
   case object UnknownMethod extends ErrorCode {
     override def code: String = "unknownMethod"
-
-    override def defaultDescription: String = null
   }
 
   case object AccountNotFound extends ErrorCode {
     override def code: String = "accountNotFound"
-
-    override def defaultDescription: String = null
   }
 }
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/routes/JMAPApiRoutes.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/routes/JMAPApiRoutes.scala
index 9623f74..d81adf6 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/routes/JMAPApiRoutes.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/routes/JMAPApiRoutes.scala
@@ -138,7 +138,7 @@ class JMAPApiRoutes (val authenticator: Authenticator,
   private def processMethodWithMatchName(capabilities: Set[CapabilityIdentifier], invocation: Invocation, mailboxSession: MailboxSession): SMono[Invocation] =
     SMono.justOrEmpty(methodsByName.get(invocation.methodName))
       .flatMap(method => SMono.fromPublisher(method.process(capabilities, invocation, mailboxSession)))
-      .onErrorResume(throwable => SMono.just(Invocation.error(ErrorCode.ServerFail, Option(throwable.getMessage), invocation.methodCallId)))
+      .onErrorResume(throwable => SMono.just(Invocation.error(ErrorCode.ServerFail, throwable.getMessage, invocation.methodCallId)))
       .switchIfEmpty(SMono.just(Invocation.error(ErrorCode.UnknownMethod, invocation.methodCallId)))
 
   private def handleError(throwable: Throwable, httpServerResponse: HttpServerResponse): SMono[Void] = throwable match {


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org