Skip to content

Commit

Permalink
Made request success check consistent between scala and scala js (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
BenFradet authored and juanpedromoreno committed May 3, 2017
1 parent b869e17 commit 46f6098
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import fr.hmil.roshttp.body.BulkBodyPart
import fr.hmil.roshttp.response.SimpleHttpResponse
import fr.hmil.roshttp.util.HeaderMap
import github4s.GithubResponses._
import github4s.HttpClient.HttpCode400
import github4s.HttpClient.{HttpCode200, HttpCode299}
import io.circe.Decoder
import io.circe.parser._

Expand Down Expand Up @@ -69,7 +69,7 @@ trait HttpRequestBuilderExtensionJS {

def toEntity[A](response: SimpleHttpResponse)(implicit D: Decoder[A]): GHResponse[A] =
response match {
case r if r.statusCode < HttpCode400.statusCode
case r if r.statusCode <= HttpCode299.statusCode && r.statusCode >= HttpCode200.statusCode
decode[A](r.body).fold(
e Either.left(JsonParsingException(e.getMessage, r.body)),
result
Expand Down
8 changes: 6 additions & 2 deletions github4s/shared/src/main/scala/github4s/HttpClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,12 @@ object HttpClient {
def statusCode: Int
}

case object HttpCode400 extends HttpStatus {
def statusCode = 400
case object HttpCode200 extends HttpStatus {
def statusCode = 200
}

case object HttpCode299 extends HttpStatus {
def statusCode = 299
}
}

Expand Down

0 comments on commit 46f6098

Please sign in to comment.