Skip to content

Commit

Permalink
fix: handle unsupported PIURI found in DIDComm messages accordingly (…
Browse files Browse the repository at this point in the history
…HTTP 422 response)

Signed-off-by: Benjamin Voiturier <[email protected]>
  • Loading branch information
bvoiturier committed Oct 17, 2024
1 parent f74cc3e commit bda6443
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.hyperledger.identus.didcomm.controller

import org.hyperledger.identus.mercury.model.DidId
import org.hyperledger.identus.mercury.model.{DidId, PIURI}
import org.hyperledger.identus.shared.models.{Failure, KeyId, StatusCode}

sealed trait DIDCommControllerError extends Failure {
Expand Down Expand Up @@ -39,4 +39,10 @@ object DIDCommControllerError {
override def userFacingMessage: String =
s"The Peer DID does not contain the required key: DID=${did.value}, keyId=${keyId.value}"
}

final case class UnsupportedPIURI(piuri: PIURI) extends DIDCommControllerError {
override def statusCode: StatusCode = StatusCode.UnprocessableContent
override def userFacingMessage: String =
s"The Protocol Identifier URI (URI) found in the DIDComm message is not supported: PIURI=$piuri"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ class DIDCommControllerImpl(
/*
* Unknown Message
*/
private val handleUnknownMessage: PartialFunction[Message, UIO[String]] = { case _ =>
ZIO.succeed("Unknown Message Type")
private val handleUnknownMessage: PartialFunction[Message, IO[UnsupportedPIURI, String]] = { case msg =>
ZIO.fail(UnsupportedPIURI(msg.piuri))
}
}

Expand Down

0 comments on commit bda6443

Please sign in to comment.