@@ -26,8 +26,8 @@ class BitbucketClient(key: String, secretKey: String, token: String, secretToken
26
26
*/
27
27
def execute [T ](request : Request [T ])(implicit reader : Reads [T ]): RequestResponse [T ] = {
28
28
get(request.url) match {
29
- case Right (json) => RequestResponse ( json.asOpt [T ])
30
- case Left (error) => RequestResponse ( None , error.detail, hasError = true )
29
+ case Right (json) => json.validate [T ].fold(_ => FailedResponse ( s " Failed to parse json: $json " ), a => SuccessfulResponse (a) )
30
+ case Left (error) => FailedResponse ( error.detail)
31
31
}
32
32
}
33
33
@@ -40,14 +40,14 @@ class BitbucketClient(key: String, secretKey: String, token: String, secretToken
40
40
val nextPage = (json \ " next" ).asOpt[String ]
41
41
val nextRepos = nextPage.map {
42
42
nextUrl =>
43
- executePaginated(Request (nextUrl, request.classType)).value.getOrElse( Seq ())
44
- }.getOrElse(Seq ( ))
43
+ executePaginated(Request (nextUrl, request.classType))
44
+ }.getOrElse(SuccessfulResponse ( Seq .empty ))
45
45
46
- val values = (json \ " values" ).asOpt [Seq [T ]].getOrElse( Seq ( ))
47
- RequestResponse ( Some ( values ++ nextRepos) )
46
+ val values = (json \ " values" ).validate [Seq [T ]].fold(_ => FailedResponse ( s " Failed to parse json: $json " ), a => SuccessfulResponse (a ))
47
+ RequestResponse .apply( values, nextRepos)
48
48
49
49
case Left (error) =>
50
- RequestResponse [ Seq [ T ]]( None , error.detail, hasError = true )
50
+ FailedResponse ( error.detail)
51
51
}
52
52
}
53
53
@@ -66,13 +66,13 @@ class BitbucketClient(key: String, secretKey: String, token: String, secretToken
66
66
67
67
val jsValue = parseJson(body)
68
68
jsValue match {
69
- case Right (responseObj ) =>
70
- RequestResponse (responseObj.asOpt [T ])
69
+ case Right (json ) =>
70
+ json.validate [T ].fold(_ => FailedResponse ( s " Failed to parse json: $json " ), a => SuccessfulResponse (a) )
71
71
case Left (message) =>
72
- RequestResponse [ T ]( None , message = message .detail, hasError = true )
72
+ FailedResponse ( message.detail)
73
73
}
74
74
} else {
75
- RequestResponse [ T ]( None , result.statusText, hasError = true )
75
+ FailedResponse ( result.statusText)
76
76
}
77
77
78
78
value
@@ -103,9 +103,9 @@ class BitbucketClient(key: String, secretKey: String, token: String, secretToken
103
103
val result = Await .result(jpromise, requestTimeout)
104
104
105
105
val value = if (Seq (HTTPStatusCodes .OK , HTTPStatusCodes .CREATED , HTTPStatusCodes .NO_CONTENT ).contains(result.status)) {
106
- RequestResponse ( Option ( true ) )
106
+ SuccessfulResponse ( true )
107
107
} else {
108
- RequestResponse [ Boolean ]( None , result.statusText, hasError = true )
108
+ FailedResponse ( result.statusText)
109
109
}
110
110
111
111
value
@@ -157,7 +157,7 @@ class BitbucketClient(key: String, secretKey: String, token: String, secretToken
157
157
|
158
158
| ${getFullStackTrace(error)}
159
159
""" .stripMargin
160
- RequestResponse [ T ]( None , statusMessage, hasError = true )
160
+ FailedResponse ( statusMessage)
161
161
}
162
162
}
163
163
0 commit comments