Scoop API

scoop:scoop.http.client:0.1.0

src/authentication/failure.scoop

Selected production source · src/authentication/failure.scoop

1package scoop.http.client
3import scoop.http.HttpResponseHead
4import scoop.url.Url
6/**
7 * The reason authentication could not complete.
8 */
9public enum HttpAuthenticationFailure {
10 /**
11 * The peer challenge is malformed or incompatible with the provider.
12 */
13 InvalidChallenge,
14 /**
15 * The supplied credentials cannot be encoded or used for the selected scheme.
16 */
17 InvalidCredentials,
18 /**
19 * The peer authentication response failed validation.
20 */
21 InvalidResponse,
22 /**
23 * Authentication requires another attempt with a body that cannot be replayed.
24 */
25 BodyNotReplayable,
26 /**
27 * The peer rejected the attempted authentication.
28 */
29 Rejected,
30 /**
31 * The authentication attempt limit was reached.
32 */
33 LimitExceeded }
35/**
36 * Authentication failed, retaining its reason, URL, response head, and optional underlying cause.
37 */
38public class HttpAuthenticationException public constructor(
39 /**
40 * The authentication failure category.
41 */
42 public val reason: HttpAuthenticationFailure,
43 /**
44 * The request URL whose authentication failed.
45 */
46 public val url: Url,
47 /**
48 * The peer response head associated with failure.
49 */
50 public val head: HttpResponseHead? = None,
51 /**
52 * The underlying failure, when present.
53 */
54 public val cause: Throwable? = None
55) : Exception(Some(authenticationFailureText(reason)))
57private fun authenticationFailureText(reason: HttpAuthenticationFailure): String = when (reason) {
58 case InvalidChallenge -> "invalid HTTP authentication challenge"
59 case InvalidCredentials -> "invalid HTTP authentication credentials"
60 case InvalidResponse -> "invalid HTTP authentication response"
61 case BodyNotReplayable -> "HTTP authentication requires a replayable request body"
62 case Rejected -> "HTTP authentication credentials were rejected"
63 case LimitExceeded -> "HTTP authentication attempt limit exceeded"