Skip to content

Commit

Permalink
fix: Replaces ngx error call with kong corresponding one
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanlazaro1 committed Dec 21, 2023
1 parent a4d0a6a commit 091e0f0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion template-transformer/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ function TemplateTransformerHandler:body_filter(config)
if gmatch(content_type, "(application/json)")() then
body = read_json_body(raw_body)
if body == nil then
return ngx.ERROR
return kong.response.error(ngx.HTTP_INTERNAL_SERVER_ERROR)
end
local req_query_string = req_get_uri_args()
local router_matches = ngx.ctx.router_matches
Expand Down
11 changes: 6 additions & 5 deletions template-transformer/spec/handler_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ local kong = {
}
},
response = {
get_source = function ()
return "service"
end
get_source = function () return "service" end,
error = spy.new(function () return "ERROR" end)
}
}

Expand Down Expand Up @@ -51,6 +50,7 @@ local ngx = {
custom_data = { important_stuff = 123 }
},
status = 200,
HTTP_INTERNAL_SERVER_ERROR = 500
}
_G.ngx = ngx
_G.kong = kong
Expand Down Expand Up @@ -427,13 +427,14 @@ describe("Test TemplateTransformerHandler body_filter", function()
it("should call and return ngx error when body is ready and not JSON", function()
mock_resp_headers = {}
ngx.arg[1] = nil
ngx.ERROR = "error"
local expected = "ERROR"
local config = {
response_template = '{ "bar" : "{{body.foo}}" }'
}
_G.ngx.ctx.buffer = '<html>'
actual = TemplateTransformerHandler:body_filter(config)
assert.equal(ngx.ERROR, actual)
assert.equal(expected, actual)
assert.spy(kong.response.error).was_called_with(500)
assert.is_nil(ngx.arg[1])
end)

Expand Down

0 comments on commit 091e0f0

Please sign in to comment.