-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rejection.scala
147 lines (125 loc) · 5.46 KB
/
Rejection.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package pl.iterators.stir.server
import org.http4s.{ Challenge, DecodeFailure, Method }
trait Rejection
/**
* Rejection created by the `validation` directive as well as for `IllegalArgumentExceptions`
* thrown by domain model constructors (e.g. via `require`).
* It signals that an expected value was semantically invalid.
*/
case class ValidationRejection(message: String, cause: Option[Throwable]) extends Rejection
/**
* Rejection created by unmarshallers.
* Signals that the request was rejected because the requests content-type is unsupported.
*/
case class EntityRejection(e: DecodeFailure) extends Rejection
/**
* Rejection created by unmarshallers.
* Signals that the request was rejected because unmarshalling failed with an error that wasn't
* an `IllegalArgumentException`. Usually that means that the request content was not of the expected format.
* Note that semantic issues with the request content (e.g. because some parameter was out of range)
* will usually trigger a `ValidationRejection` instead.
*/
case class MalformedRequestContentRejection(message: String, cause: Throwable) extends Rejection
/**
* Rejection created by parameter filters.
* Signals that the request was rejected because a query parameter value was not equal to required one.
*/
final case class InvalidRequiredValueForQueryParamRejection(parameterName: String, expectedValue: String,
actualValue: String) extends Rejection
/**
* Rejection created by parameter filters.
* Signals that the request was rejected because a query parameter was not found.
*/
final case class MissingQueryParamRejection(parameterName: String) extends Rejection
/**
* Rejection created by parameter filters.
* Signals that the request was rejected because a query parameter could not be interpreted.
*/
final case class MalformedQueryParamRejection(parameterName: String, errorMsg: String, cause: Option[Throwable] = None)
extends Rejection
/**
* Rejection created by header directives.
* Signals that the request was rejected because a header value is malformed.
*/
final case class MalformedHeaderRejection(headerName: String, errorMsg: String, cause: Option[Throwable] = None)
extends Rejection
/**
* Rejection created by header directives.
* Signals that the request was rejected because a required header could not be found.
*/
final case class MissingHeaderRejection(headerName: String) extends Rejection
/**
* Rejection created by method filters.
* Signals that the request was rejected because the HTTP method is unsupported.
*/
final case class MethodRejection(supported: Method) extends Rejection
/**
* Rejection created by the `cookie` directive.
* Signals that the request was rejected because a cookie was not found.
*/
final case class MissingCookieRejection(cookieName: String) extends Rejection
/**
* A special Rejection that serves as a container for a transformation function on rejections.
* It is used by some directives to "cancel" rejections that are added by later directives of a similar type.
*
* Consider this route structure for example:
*
* {{{
* put { reject(ValidationRejection("no") } ~ get { ... }
* }}}
*
* If this structure is applied to a PUT request the list of rejections coming back contains three elements:
*
* 1. A ValidationRejection
* 2. A MethodRejection
* 3. A TransformationRejection holding a function filtering out the MethodRejection
*
* so that in the end the RejectionHandler will only see one rejection (the ValidationRejection), because the
* MethodRejection added by the `get` directive is canceled by the `put` directive (since the HTTP method
* did indeed match eventually).
*/
final case class TransformationRejection(transform: Seq[Rejection] => Seq[Rejection]) extends Rejection
/**
* Rejection created by the various [[pl.iterators.stir.server.directives.SecurityDirectives]].
* Signals that the request was rejected because the user could not be authenticated. The reason for the rejection is
* specified in the cause.
*/
final case class AuthenticationFailedRejection(cause: AuthenticationFailedRejection.Cause, challenge: Challenge)
extends Rejection
object AuthenticationFailedRejection {
/**
* Signals the cause of the failed authentication.
*/
sealed trait Cause
/**
* Signals the cause of the rejecting was that the user could not be authenticated, because the `WWW-Authenticate`
* header was not supplied.
*/
case object CredentialsMissing extends Cause
/**
* Signals the cause of the rejecting was that the user could not be authenticated, because the supplied credentials
* are invalid.
*/
case object CredentialsRejected extends Cause
}
/**
* Rejection created by the 'authorize' directive.
* Signals that the request was rejected because the user is not authorized.
*/
case object AuthorizationFailedRejection extends Rejection
/**
* Rejection created by form field filters.
* Signals that the request was rejected because a form field was not found.
*/
final case class MissingFormFieldRejection(fieldName: String) extends Rejection
/**
* Rejection created by form field filters.
* Signals that the request was rejected because a form field could not be interpreted.
*/
final case class MalformedFormFieldRejection(fieldName: String, errorMsg: String, cause: Option[Throwable] = None)
extends Rejection
/**
* Rejection created by scheme filters.
* Signals that the request was rejected because the Uri scheme is unsupported.
*/
final case class SchemeRejection(supported: String) extends Rejection