claudiajs / claudia-api-builder

Use AWS API Gateway as if it were a lightweight JavaScript web server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ApiBuilder.ApiResponse is not a constructor error @ claudia-api-builder v3.0.x

identityclash opened this issue · comments

Using "claudia-api-builder": "^3.0.1":

The snippet below is supposed to return an error 400, but instead is throwing an internal server error.

const ApiBuilder = require('claudia-api-builder');
const api = new ApiBuilder();

api.get('/error', function () {
  return new ApiBuilder.ApiResponse({ message: 'Failed validation!' }, {'Content-Type': 'application/json'}, 400);
});
  • Expected behaviour:
    API returns an error 400 along with the error message.

  • What actually happens:
    HTTP status code is 500.

{
    "errorMessage": "ApiBuilder.ApiResponse is not a constructor"
}

The static ApiBuilder constructor became available in 4.1.0, so you’ll have to upgrade if you want to use that syntax. Otherwise, use return new api.ApiResponse....