-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Pat Losoponkul
committed
Apr 17, 2023
1 parent
e3e7a4c
commit b2212c1
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
.../service/server/src/main/scala/io/iohk/atala/castor/controller/http/EndpointOutputs.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.iohk.atala.castor.controller.http | ||
|
||
import sttp.model.StatusCode | ||
import sttp.tapir.* | ||
import sttp.tapir.json.zio.jsonBody | ||
import io.iohk.atala.castor.controller.http.DIDResolutionResult | ||
|
||
object EndpointOutputs { | ||
|
||
private def resolutionErrorMather(err: String): PartialFunction[Any, Boolean] = { | ||
case res: DIDResolutionResult if res.didResolutionMetadata.error.contains(err) => true | ||
} | ||
|
||
// https://w3c-ccg.github.io/did-resolution/#bindings-https | ||
private val resolutionErrorHttpStatusBinding = Seq[(String, StatusCode)]( | ||
"invalidDid" -> StatusCode.BadRequest, | ||
"invalidDidUrl" -> StatusCode.BadRequest, | ||
"notFound" -> StatusCode.NotFound, | ||
"representationNotSupported" -> StatusCode.NotAcceptable, | ||
"methodNotSupported" -> StatusCode.NotImplemented, | ||
"internalError" -> StatusCode.InternalServerError | ||
).map { case (msg, code) => | ||
oneOfVariantValueMatcher(code, jsonBody[DIDResolutionResult])(resolutionErrorMather(msg)) | ||
} | ||
|
||
val resolutionError: EndpointOutput[DIDResolutionResult] = oneOf( | ||
resolutionErrorHttpStatusBinding.head, | ||
resolutionErrorHttpStatusBinding.tail: _* | ||
) | ||
|
||
} |