This is an automated email from the ASF dual-hosted git repository. rcordier pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
The following commit(s) were added to refs/heads/master by this push: new 8169d36bef [FIX] Change log level for JMAP errors 8169d36bef is described below commit 8169d36bef2108249f8c088afac3e10060e14b93 Author: Quan Tran <hqt...@linagora.com> AuthorDate: Mon Apr 29 12:48:45 2024 +0700 [FIX] Change log level for JMAP errors User input errors => INFO Server side errors => ERROR --- .../org/apache/james/jmap/method/Method.scala | 62 ++++++++++++++-------- 1 file changed, 40 insertions(+), 22 deletions(-) diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/Method.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/Method.scala index 3816b8099a..6aa766d9ae 100644 --- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/Method.scala +++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/Method.scala @@ -100,42 +100,60 @@ trait MethodRequiringAccountId[REQUEST <: WithAccountId] extends Method { translatedMailboxSession = sessionTranslator.delegateIfNeeded(mailboxSession, request.accountId) } yield { translatedMailboxSession.flatMapMany(translatedSession => - SFlux(doProcess(capabilities, invocation, translatedSession, request)) - .doOnError(e => MDCStructuredLogger.forLogger(Method.LOGGER) - .field("protocol", "JMAP") - .field("username", mailboxSession.getUser.asString()) - .field("method", invocation.invocation.methodName.value.value) - .log(logger => logger.error("Failed executing a JMAP method", e)))) + SFlux(doProcess(capabilities, invocation, translatedSession, request))) } + def logClientSideError(e: Exception): Unit = + MDCStructuredLogger.forLogger(Method.LOGGER) + .field("protocol", "JMAP") + .field("username", mailboxSession.getUser.asString()) + .field("method", invocation.invocation.methodName.value.value) + .log(logger => logger.info("Client side error executing a JMAP method", e)) + val result: SFlux[InvocationWithContext] = SFlux.fromPublisher(either.fold(e => SFlux.error[InvocationWithContext](e), r => r)) .onErrorResume[InvocationWithContext] { - case _: AccountNotFoundException => SFlux.just[InvocationWithContext] (InvocationWithContext(Invocation.error(ErrorCode.AccountNotFound, invocation.invocation.methodCallId), invocation.processingContext)) - case _: ForbiddenAccountManagementException => SFlux.just[InvocationWithContext] (InvocationWithContext(Invocation.error(ErrorCode.Forbidden, - "Access to other accounts settings is forbidden", - invocation.invocation.methodCallId), invocation.processingContext)) + case e: AccountNotFoundException => SFlux.just[InvocationWithContext] (InvocationWithContext(Invocation.error(ErrorCode.AccountNotFound, invocation.invocation.methodCallId), invocation.processingContext)) + .doOnNext(_ => logClientSideError(e)) + case e: ForbiddenAccountManagementException => SFlux.just[InvocationWithContext] (InvocationWithContext(Invocation.error(ErrorCode.Forbidden, + "Access to other accounts settings is forbidden", + invocation.invocation.methodCallId), invocation.processingContext)) + .doOnNext(_ => logClientSideError(e)) case e: UnsupportedRequestParameterException => SFlux.just[InvocationWithContext] (InvocationWithContext(Invocation.error( - ErrorCode.InvalidArguments, - s"The following parameter ${e.unsupportedParam} is syntactically valid, but is not supported by the server.", - invocation.invocation.methodCallId), invocation.processingContext)) + ErrorCode.InvalidArguments, + s"The following parameter ${e.unsupportedParam} is syntactically valid, but is not supported by the server.", + invocation.invocation.methodCallId), invocation.processingContext)) + .doOnNext(_ => logClientSideError(e)) case e: UnsupportedSortException => SFlux.just[InvocationWithContext] (InvocationWithContext(Invocation.error( - ErrorCode.UnsupportedSort, - s"The sort ${e.unsupportedSort} is syntactically valid, but it includes a property the server does not support sorting on or a collation method it does not recognise.", - invocation.invocation.methodCallId), invocation.processingContext)) + ErrorCode.UnsupportedSort, + s"The sort ${e.unsupportedSort} is syntactically valid, but it includes a property the server does not support sorting on or a collation method it does not recognise.", + invocation.invocation.methodCallId), invocation.processingContext)) + .doOnNext(_ => logClientSideError(e)) case e: UnsupportedFilterException => SFlux.just[InvocationWithContext] (InvocationWithContext(Invocation.error( - ErrorCode.UnsupportedFilter, - s"The filter ${e.unsupportedFilter} is syntactically valid, but the server cannot process it. If the filter was the result of a user’s search input, the client SHOULD suggest that the user simplify their search.", - invocation.invocation.methodCallId), invocation.processingContext)) + ErrorCode.UnsupportedFilter, + s"The filter ${e.unsupportedFilter} is syntactically valid, but the server cannot process it. If the filter was the result of a user’s search input, the client SHOULD suggest that the user simplify their search.", + invocation.invocation.methodCallId), invocation.processingContext)) + .doOnNext(_ => logClientSideError(e)) case e: UnsupportedNestingException => SFlux.just[InvocationWithContext] (InvocationWithContext(Invocation.error( - ErrorCode.UnsupportedFilter, - description = e.message, - invocation.invocation.methodCallId), invocation.processingContext)) + ErrorCode.UnsupportedFilter, + description = e.message, + invocation.invocation.methodCallId), invocation.processingContext)) + .doOnNext(_ => logClientSideError(e)) case e: IllegalArgumentException => SFlux.just[InvocationWithContext] (InvocationWithContext(Invocation.error(ErrorCode.InvalidArguments, e.getMessage, invocation.invocation.methodCallId), invocation.processingContext)) + .doOnNext(_ => logClientSideError(e)) case e: MailboxNotFoundException => SFlux.just[InvocationWithContext] (InvocationWithContext(Invocation.error(ErrorCode.InvalidArguments, e.getMessage, invocation.invocation.methodCallId), invocation.processingContext)) + .doOnNext(_ => logClientSideError(e)) case e: ChangeNotFoundException => SFlux.just[InvocationWithContext] (InvocationWithContext(Invocation.error(ErrorCode.CannotCalculateChanges, e.getMessage, invocation.invocation.methodCallId), invocation.processingContext)) + .doOnNext(_ => logClientSideError(e)) case e: RequestTooLargeException => SFlux.just[InvocationWithContext] (InvocationWithContext(Invocation.error(ErrorCode.RequestTooLarge, e.description, invocation.invocation.methodCallId), invocation.processingContext)) + .doOnNext(_ => logClientSideError(e)) case e: IdentityIdNotFoundException => SFlux.just[InvocationWithContext] (InvocationWithContext(Invocation.error(ErrorCode.InvalidArguments, e.description, invocation.invocation.methodCallId), invocation.processingContext)) + .doOnNext(_ => logClientSideError(e)) case e: Throwable => SFlux.error[InvocationWithContext] (e) + .doOnError(e => MDCStructuredLogger.forLogger(Method.LOGGER) + .field("protocol", "JMAP") + .field("username", mailboxSession.getUser.asString()) + .field("method", invocation.invocation.methodName.value.value) + .log(logger => logger.error("Server side error executing a JMAP method", e))) } metricFactory.decoratePublisherWithTimerMetric(JMAP_RFC8621_PREFIX + methodName.value, result) --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@james.apache.org For additional commands, e-mail: notifications-h...@james.apache.org