Skip to content

Commit

Permalink
Merge pull request #1818 from dherault/revert-1796-raise-500-on-pytho…
Browse files Browse the repository at this point in the history
…n-error

Revert "fix: return 500 Internal Server Error on python error"
  • Loading branch information
dherault authored Aug 30, 2024
2 parents a1281bb + bbe5e7a commit 79288e7
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 28 deletions.
13 changes: 5 additions & 8 deletions src/events/http/HttpServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ export default class HttpServer {
/* RESPONSE SELECTION (among endpoint's possible responses) */

// Failure handling
let errorStatusCode = "500"
let errorStatusCode = "502"

if (err) {
const errorMessage = (err.message || err).toString()
Expand All @@ -655,17 +655,14 @@ export default class HttpServer {
if (found && found.length > 1) {
;[, errorStatusCode] = found
} else {
errorStatusCode = "500"
errorStatusCode = "502"
}

// Mocks Lambda errors
result = {
body: JSON.stringify({
message: errorMessage,
stackTrace: this.#getArrayStackTrace(err.stack),
type: err.constructor.name,
}),
statusCode: errorStatusCode,
errorMessage,
errorType: err.constructor.name,
stackTrace: this.#getArrayStackTrace(err.stack),
}

log.error(errorMessage)
Expand Down
4 changes: 2 additions & 2 deletions src/lambda/handler-runner/python-runner/PythonRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ export default class PythonRunner {
})

const onErr = (data) => {
log.notice(data.toString())
// TODO

rej(new Error("Internal Server Error"))
log.notice(data.toString())
}

const onLine = (line) => {
Expand Down
3 changes: 0 additions & 3 deletions tests/runtimes/python/python3/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,3 @@ def hello(event, context):
"body": json.dumps(body),
"statusCode": 200,
}

def error(event, context):
raise Exception("This is an error")
9 changes: 0 additions & 9 deletions tests/runtimes/python/python3/python3.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,4 @@ describe("Python 3 tests", function desc() {
assert.deepEqual(json, expected)
})
})

it("should return a 500 on error", async () => {
const url = new URL("/dev/error", BASE_URL)
const response = await fetch(url)
const json = await response.json()

assert.equal(response.status, 500)
assert.equal(json.message, "Internal Server Error")
})
})
6 changes: 0 additions & 6 deletions tests/runtimes/python/python3/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,3 @@ functions:
method: get
path: hello
handler: handler.hello
error:
events:
- http:
method: get
path: error
handler: handler.error

0 comments on commit 79288e7

Please sign in to comment.