Skip to content

Allow web actions to respond with non-standard status codes #5146

Closed
@rabbah

Description

@rabbah

Environment details:

  • local deployment (standalone openwhisk)

Steps to reproduce the issue:

  1. create a web action using this function:
> cat t.js
const main = () => ({
  "body": {
    "message": "hello"
  },
  "statusCode": 442
})
  1. invoke the web action
> wsk action update t t.js --web true
> curl -X POST `wsk action get t --url`
{
  "code": "b86c3c15bed0763357caa327bd2f25e4",
  "error": "Response is not valid 'message/http'."
}

Expecting the API to work (return the message) but it does not.
Change the statusCode to 400 and the API works as expected.

The relevant logic is here

val code = fields.get(rp.statusCode).map {
case JsNumber(c) =>
// the following throws an exception if the code is not a whole number or a valid code
StatusCode.int2StatusCode(c.toIntExact)
case JsString(c) =>
// parse the string to an Int (not a BigInt) matching JsNumber case match above
// c.toInt could throw an exception if the string isn't an integer
StatusCode.int2StatusCode(c.toInt)
case _ => throw new Throwable("Illegal status code")
}

This is an error in the controller for status code 442 but it is swallowed. Amending the Try logic to show the exceptions produces:

exception in resultAsHttp: java.lang.RuntimeException: 
Non-standard status codes cannot be created by implicit conversion. 
Use `StatusCodes.custom` instead.

For reference, this is the cited message:
https://github.com/akka/akka-http/blob/5f8fb8c29285dcef16d74704394a7f6acf4f544e/akka-http-core/src/main/scala/akka/http/scaladsl/model/StatusCode.scala#L87

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions