@@ -29,6 +29,7 @@ import akka.http.scaladsl.model.MediaType
29
29
import akka .http .scaladsl .model .MediaTypes
30
30
import akka .http .scaladsl .model .MediaTypes ._
31
31
import akka .http .scaladsl .model .StatusCodes ._
32
+ import akka .http .scaladsl .model .StatusCodes
32
33
import akka .http .scaladsl .model .StatusCode
33
34
import akka .http .scaladsl .model .headers .RawHeader
34
35
import akka .http .scaladsl .model .headers ._
@@ -40,7 +41,7 @@ import akka.http.scaladsl.model.headers.`Timeout-Access`
40
41
import akka .http .scaladsl .model .ContentType
41
42
import akka .http .scaladsl .model .ContentTypes
42
43
import akka .http .scaladsl .model .FormData
43
- import akka .http .scaladsl .model .HttpMethods .{ OPTIONS }
44
+ import akka .http .scaladsl .model .HttpMethods .OPTIONS
44
45
import akka .http .scaladsl .model .HttpCharsets
45
46
import akka .http .scaladsl .model .HttpResponse
46
47
import spray .json ._
@@ -248,18 +249,19 @@ protected[core] object WhiskWebActionsApi extends Directives {
248
249
249
250
val body = fields.get(" body" )
250
251
251
- val code = fields.get(rp.statusCode).map {
252
- case JsNumber (c) =>
253
- // the following throws an exception if the code is not a whole number or a valid code
254
- StatusCode .int2StatusCode(c.toIntExact)
255
- case JsString (c) =>
256
- // parse the string to an Int (not a BigInt) matching JsNumber case match above
257
- // c.toInt could throw an exception if the string isn't an integer
258
- StatusCode .int2StatusCode(c.toInt)
252
+ val intCode = fields.get(rp.statusCode).map {
253
+ // the following throws an exception if the code is not a whole number or a valid code
254
+ case JsNumber (c) => c.toIntExact
255
+
256
+ // parse the string to an Int (not a BigInt) matching JsNumber case match above
257
+ // c.toInt could throw an exception if the string isn't an integer
258
+ case JsString (c) => c.toInt
259
259
260
260
case _ => throw new Throwable (" Illegal status code" )
261
261
}
262
262
263
+ val code : Option [StatusCode ] = intCode.map(c => StatusCodes .getForKey(c).getOrElse(StatusCodes .custom(c, " " )))
264
+
263
265
body.collect {
264
266
case JsString (str) if str.nonEmpty => interpretHttpResponse(code.getOrElse(OK ), headers, str, transid)
265
267
case JsString (str) /* str.isEmpty */ => respondWithEmptyEntity(code.getOrElse(NoContent ), headers)
@@ -268,7 +270,7 @@ protected[core] object WhiskWebActionsApi extends Directives {
268
270
269
271
} getOrElse {
270
272
// either the result was not a JsObject or there was an exception validating the
271
- // response as an http result
273
+ // response as an http result (including an invalid status code)
272
274
terminate(BadRequest , Messages .invalidMedia(`message/http`))(transid, jsonPrettyPrinter)
273
275
}
274
276
}
0 commit comments