• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

input-output-hk / atala-prism-building-blocks / 5276709076

15 Jun 2023 08:45AM UTC coverage: 27.472% (+0.4%) from 27.056%
5276709076

Pull #543

patlo-iog
chore: change default devMode config to false
Pull Request #543: feat(prism-agent): integrate DID secret storage with Vault

115 of 115 new or added lines in 11 files covered. (100.0%)

2484 of 9042 relevant lines covered (27.47%)

0.27 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

42.86
/prism-agent/service/server/src/main/scala/io/iohk/atala/api/http/ErrorResponse.scala
1
package io.iohk.atala.api.http
2

3
import io.iohk.atala.api.http.ErrorResponse.annotations
4
import sttp.model.StatusCode
5
import sttp.tapir.EndpointOutput.OneOf
6
import sttp.tapir.Schema
7
import sttp.tapir.Schema.annotations.{description, encodedExample}
8
import sttp.tapir.generic.auto.*
9
import sttp.tapir.json.zio.jsonBody
10
import sttp.tapir.server.model.ValuedEndpointOutput
11
import zio.json.{DeriveJsonDecoder, DeriveJsonEncoder}
12

13
case class ErrorResponse(
14
    @description(annotations.status.description)
15
    @encodedExample(annotations.status.example)
16
    status: Int,
17
    @description(annotations.`type`.description)
18
    @encodedExample(annotations.`type`.example)
19
    `type`: String,
20
    @description(annotations.title.description)
21
    @encodedExample(annotations.title.example)
22
    title: String,
23
    @description(annotations.detail.description)
24
    @encodedExample(annotations.detail.example)
25
    detail: Option[String],
26
    @description(annotations.instance.description)
27
    @encodedExample(annotations.instance.example)
28
    instance: String
29
)
30

31
object ErrorResponse {
32
  given encoder: zio.json.JsonEncoder[ErrorResponse] = DeriveJsonEncoder.gen[ErrorResponse]
33

34
  given decoder: zio.json.JsonDecoder[ErrorResponse] = DeriveJsonDecoder.gen[ErrorResponse]
35

36
  given schema: Schema[ErrorResponse] = Schema.derived
37

38
  def failureResponseHandler(msg: String): ValuedEndpointOutput[_] =
39
    ValuedEndpointOutput(jsonBody[ErrorResponse], ErrorResponse.badRequest(detail = Option(msg)))
40

41
  object annotations {
42
    object status
43
        extends Annotation[Int](
44
          description = "The HTTP status code for this occurrence of the problem.",
45
          example = 200
46
        )
47
    object `type`
48
        extends Annotation[String](
49
          description = "A URI reference that identifies the problem type.",
50
          example = "https://example.org/doc/#model-MalformedEmail/"
51
        )
52

53
    object title
54
        extends Annotation[String](
55
          description =
56
            "A short, human-readable summary of the problem type. It does not change from occurrence to occurrence of the problem.",
57
          example = "Malformed email"
58
        )
59

60
    object detail
61
        extends Annotation[Option[String]](
62
          description = "A human-readable explanation specific to this occurrence of the problem.",
63
          example = Option("The received '{}à!è@!.b}' email does not conform to the email format")
64
        )
65

66
    object instance
67
        extends Annotation[String](
68
          description =
69
            "A URI reference that identifies the specific occurrence of the problem. It may or may not yield further information if dereferenced.",
70
          example = "The received '{}à!è@!.b}' email does not conform to the email format"
71
        )
72
  }
73

74
  def notFound(title: String = "NotFound", detail: Option[String] = None, instance: String = "") =
75
    ErrorResponse(StatusCode.NotFound.code, `type` = "NotFound", title = title, detail = detail, instance = instance)
76

77
  def internalServerError(title: String = "InternalServerError", detail: Option[String] = None, instance: String = "") =
78
    ErrorResponse(
79
      StatusCode.InternalServerError.code,
80
      `type` = "InternalServerError",
81
      title = title,
82
      detail = detail,
83
      instance = instance
84
    )
85

86
  def badRequest(title: String = "BadRequest", detail: Option[String] = None, instance: String = "") =
87
    ErrorResponse(
88
      StatusCode.BadRequest.code,
89
      `type` = title,
90
      title = title,
91
      detail = detail,
92
      instance = instance
93
    )
94

95
  def unprocessableEntity(title: String = "UnprocessableEntity", detail: Option[String] = None, instance: String = "") =
96
    ErrorResponse(
97
      StatusCode.UnprocessableEntity.code,
98
      `type` = title,
99
      title = title,
100
      detail = detail,
101
      instance = instance
102
    )
103

104
  def conflict(title: String = "Conflict", detail: Option[String] = None, instance: String = "") =
105
    ErrorResponse(
106
      StatusCode.Conflict.code,
107
      `type` = title,
108
      title = title,
109
      detail = detail,
110
      instance = instance
111
    )
112
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc