-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Credential Defintion Error Handling Part 2 #1155
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,7 @@ import org.hyperledger.identus.api.http.* | |
import org.hyperledger.identus.api.http.model.{CollectionStats, Order, Pagination} | ||
import org.hyperledger.identus.castor.core.model.did.{LongFormPrismDID, PrismDID} | ||
import org.hyperledger.identus.pollux.core.model.schema.CredentialDefinition.FilteredEntries | ||
import org.hyperledger.identus.pollux.core.service.CredentialDefinitionService | ||
import org.hyperledger.identus.pollux.core.service.CredentialDefinitionService.Error.* | ||
import org.hyperledger.identus.pollux.core.service.{CredentialDefinitionService, CredentialDefinitionServiceError} | ||
import org.hyperledger.identus.pollux.credentialdefinition | ||
import org.hyperledger.identus.pollux.credentialdefinition.controller.CredentialDefinitionController.domainToHttpErrorIO | ||
import org.hyperledger.identus.pollux.credentialdefinition.http.{ | ||
|
@@ -37,8 +36,8 @@ class CredentialDefinitionControllerImpl(service: CredentialDefinitionService, m | |
.create(toDomain(in)) | ||
.map(cs => fromDomain(cs).withBaseUri(rc.request.uri)) | ||
} yield result).mapError { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See previous comment => There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
case e: ErrorResponse => e | ||
case e: CredentialDefinitionService.Error => CredentialDefinitionController.domainToHttpError(e) | ||
case e: ErrorResponse => e | ||
case e: CredentialDefinitionServiceError => CredentialDefinitionController.domainToHttpError(e) | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,7 @@ package org.hyperledger.identus.pollux.credentialschema.controller | |
|
||
import org.hyperledger.identus.api.http.* | ||
import org.hyperledger.identus.api.http.model.{Order, Pagination} | ||
import org.hyperledger.identus.pollux.core.service.CredentialSchemaService | ||
import org.hyperledger.identus.pollux.core.service.CredentialSchemaService.* | ||
import org.hyperledger.identus.pollux.core.service.CredentialSchemaServiceError | ||
import org.hyperledger.identus.pollux.credentialschema.http.{ | ||
CredentialSchemaInput, | ||
CredentialSchemaResponse, | ||
|
@@ -49,11 +48,11 @@ trait CredentialSchemaController { | |
|
||
object CredentialSchemaController { | ||
def domainToHttpError( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above (obsolete) 😉 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
error: CredentialSchemaService.Error | ||
error: CredentialSchemaServiceError | ||
): ErrorResponse = error | ||
|
||
implicit def domainToHttpErrorIO[R, T]( | ||
domainIO: ZIO[R, CredentialSchemaService.Error, T] | ||
domainIO: ZIO[R, CredentialSchemaServiceError, T] | ||
): ZIO[R, ErrorResponse, T] = { | ||
domainIO.mapError(domainToHttpError) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ import zio.{IO, ZIO} | |
import java.util.UUID | ||
|
||
trait CredentialDefinitionService { | ||
private[service] type Result[T] = ZIO[WalletAccessContext, CredentialDefinitionService.Error, T] | ||
private[service] type Result[T] = ZIO[WalletAccessContext, CredentialDefinitionServiceError, T] | ||
|
||
/** @param in | ||
* CredentialDefinition form for creating the instance | ||
|
@@ -23,7 +23,7 @@ trait CredentialDefinitionService { | |
* @return | ||
* The instance of the credential definition or credential service error | ||
*/ | ||
def getByGUID(guid: UUID): IO[CredentialDefinitionService.Error, CredentialDefinition] | ||
def getByGUID(guid: UUID): IO[CredentialDefinitionServiceError, CredentialDefinition] | ||
|
||
def delete(guid: UUID): Result[CredentialDefinition] | ||
|
||
|
@@ -38,22 +38,15 @@ object CredentialDefinitionService { | |
|
||
final case class RepositoryError(cause: Throwable) extends Error | ||
|
||
final case class GuidNotFoundError(guid: UUID) extends Error { | ||
def message = s"Credential Definition record cannot be found by `guid`=$guid" | ||
} | ||
final case class IdNotFoundError(id: UUID) extends Error { | ||
def message = s"Credential Definition record cannot be found by `id`=$id" | ||
} | ||
final case class NotFoundError(guid: Option[UUID] = None, id: Option[UUID] = None, message: String) extends Error | ||
|
||
// final case class NotFoundError(guid: Option[UUID] = None, id: Option[UUID] = None, message: String) extends Error | ||
object NotFoundError { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess these case classes are obsolete. We now rely on the new There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
def byGuid(guid: UUID): NotFoundError = | ||
NotFoundError(guid = Option(guid), message = s"Credential Definition record cannot be found by `guid`=$guid") | ||
|
||
// object NotFoundError { | ||
// def byGuid(guid: UUID): NotFoundError = | ||
// NotFoundError(guid = Option(guid), message = s"Credential Definition record cannot be found by `guid`=$guid") | ||
|
||
// def byId(id: UUID): NotFoundError = | ||
// NotFoundError(id = Option(id), message = s"Credential Definition record cannot be found by `id`=$id") | ||
// } | ||
def byId(id: UUID): NotFoundError = | ||
NotFoundError(id = Option(id), message = s"Credential Definition record cannot be found by `id`=$id") | ||
} | ||
|
||
final case class UpdateError(id: UUID, version: String, author: String, message: String) extends Error | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.hyperledger.identus.pollux.core.service | ||
|
||
import org.hyperledger.identus.pollux.core.model.error.CredentialSchemaError | ||
import org.hyperledger.identus.pollux.core.model.schema.CredentialSchema | ||
import org.hyperledger.identus.pollux.core.model.schema.CredentialSchema.* | ||
import org.hyperledger.identus.shared.models.{Failure, StatusCode} | ||
|
||
import java.util.UUID | ||
|
||
sealed trait CredentialDefinitionServiceError( | ||
val statusCode: StatusCode, | ||
val userFacingMessage: String | ||
) extends Failure { | ||
override val namespace = "CredentialDefinition" | ||
} | ||
|
||
final case class CredentialDefinitionGuidNotFoundError(guid: UUID) | ||
extends CredentialDefinitionServiceError( | ||
StatusCode.NotFound, | ||
s"Credential Definition record cannot be found by `guid`=$guid" | ||
) | ||
|
||
final case class CredentialDefinitionUpdateError(id: UUID, version: String, author: String, message: String) | ||
extends CredentialDefinitionServiceError( | ||
StatusCode.BadRequest, | ||
s"Credential Definition update error: id=$id, version=$version, author=$author, msg=$message" | ||
) | ||
|
||
final case class CredentialDefinitionCreationError(msg: String) | ||
extends CredentialDefinitionServiceError( | ||
StatusCode.BadRequest, | ||
s"Credential Definition Creation Error=${msg}" | ||
) | ||
|
||
final case class CredentialDefinitionValidationError(cause: CredentialSchemaError) | ||
extends CredentialDefinitionServiceError( | ||
StatusCode.BadRequest, | ||
s"Credential Definition Validation Error=${cause.message}" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not needed anymore. An implicit conversion
Failure
->ErrorResponse
is already defined in the companion object of the latter.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed