Permalink
Browse files

Store the HttpResponse in the HttpStatusException

  • Loading branch information...
1 parent 579bc6d commit 81dac03a93f96910fac1bb8d83982c760df7f017 @slackhappy slackhappy committed Jan 10, 2012
View
@@ -1,6 +1,6 @@
name := "foursquare-fhttp"
-version := "0.1"
+version := "0.1.1"
organization := "com.foursquare"
@@ -24,7 +24,7 @@ class FHttpClient ( val name: String,
case x if (x >= 200 && x < 300) =>
Future.value(response)
case code =>
- Future.exception(HttpStatusException(code, response.getStatus.getReasonPhrase).addName(name))
+ Future.exception(HttpStatusException(code, response.getStatus.getReasonPhrase, response).addName(name))
}
}
}
@@ -413,13 +413,15 @@ case class FHttpRequest ( client: FHttpClient,
}
-case class HttpStatusException(code: Int, reason: String) extends RuntimeException {
+case class HttpStatusException(code: Int, reason: String, response: HttpResponse) extends RuntimeException {
var clientId = ""
def addName(name: String) = {
clientId = " in " + name
this
}
+ def asString: String = FHttpRequest.asString(response)
+
override def getMessage(): String = {
return "HttpStatusException%s: Code: %d Reason: %s" format(clientId, code, reason)
}
@@ -197,9 +197,13 @@ class FHttpClientTest extends SpecsMatchers {
@Test
def testExceptionOnNonOKCode {
helper.responseStatus = NOT_FOUND
- val reqNotFound = FHttpRequest(client, "/notfound")
- .timeout(5000).get_!() must throwA(HttpStatusException(NOT_FOUND.getCode,
- NOT_FOUND.getReasonPhrase).addName("test-client"))
+ try {
+ val reqNotFound = FHttpRequest(client, "/notfound").timeout(5000).get_!()
+ throw new Exception("this should not have succeeded")
+ } catch {
+ case HttpStatusException(code, reason, response) if (code == NOT_FOUND.getCode) =>
+ case _ => throw new Exception("wrong code")
+ }
}

0 comments on commit 81dac03

Please sign in to comment.