#1023 - [Scala] Use status family during response processing (#1024)

* #1023 - [Scala] Use status family during response processing

* #1023 - [Scala] Use status family during response processing - adding REDIRECTION & INFORMATIONAL support
This commit is contained in:
Igor Luzhanov
2019-03-31 13:06:39 +02:00
committed by William Cheng
parent 822234dd76
commit c81c09b941
9 changed files with 519 additions and 26 deletions

View File

@@ -13,12 +13,13 @@ import com.sun.jersey.multipart.file.FileDataBodyPart
import com.wordnik.swagger.client._
import com.wordnik.swagger.client.ClientResponseReaders.Json4sFormatsReader._
import com.wordnik.swagger.client.RequestWriters.Json4sFormatsWriter._
import javax.ws.rs.core.Response.Status.Family
import java.net.URI
import java.io.File
import java.util.Date
import java.util.TimeZone
import javax.ws.rs.core.MediaType
import javax.ws.rs.core.{MediaType, Response}
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent._
@@ -144,7 +145,11 @@ class {{classname}}AsyncHelper(client: TransportClient, config: SwaggerConfig) e
val resFuture = client.submit("{{httpMethod}}", path, queryParams.toMap, headerParams.toMap, {{#bodyParam}}writer.write({{paramName}}){{/bodyParam}}{{^bodyParam}}"{{emptyBodyParam}}"{{/bodyParam}})
resFuture flatMap { resp =>
process(reader.read(resp))
val status = Response.Status.fromStatusCode(resp.statusCode)
status.getFamily match {
case Family.SUCCESSFUL | Family.REDIRECTION | Family.INFORMATIONAL => process(reader.read(resp))
case _ => throw new ApiException(resp.statusCode, resp.statusText)
}
}
}