{"record":{"id":"b040422c5533c55f","repo":"eclipse-vertx/vert.x","slug":"500-internal-server-error","errorCode":null,"errorMessage":"500 Internal Server Error","messagePattern":"500 Internal Server Error","errorType":"http","errorClass":null,"httpStatus":500,"severity":"critical","filePath":"vertx-core/src/main/java/io/vertx/core/http/HttpResponseExpectation.java","lineNumber":290,"sourceCode":"  /**\n   * 429 Too Many Requests (RFC6585)\n   */\n  HttpResponseExpectation SC_TOO_MANY_REQUESTS = status(429);\n\n  /**\n   * 431 Request Header Fields Too Large (RFC6585)\n   */\n  HttpResponseExpectation SC_REQUEST_HEADER_FIELDS_TOO_LARGE = status(431);\n\n  /**\n   * Any 5XX server error\n   */\n  HttpResponseExpectation SC_SERVER_ERRORS = status(500, 600);\n\n  /**\n   * 500 Internal Server Error\n   */\n  HttpResponseExpectation SC_INTERNAL_SERVER_ERROR = status(500);\n\n  /**\n   * 501 Not Implemented\n   */\n  HttpResponseExpectation SC_NOT_IMPLEMENTED = status(501);\n\n  /**\n   * 502 Bad Gateway\n   */\n  HttpResponseExpectation SC_BAD_GATEWAY = status(502);\n\n  /**\n   * 503 Service Unavailable\n   */\n  HttpResponseExpectation SC_SERVICE_UNAVAILABLE = status(503);\n\n  /**\n   * 504 Gateway Timeout","sourceCodeStart":272,"sourceCodeEnd":308,"githubUrl":"https://github.com/eclipse-vertx/vert.x/blob/fb308bd8c3f12c79f4ae89bef67fadf6c80d036e/vertx-core/src/main/java/io/vertx/core/http/HttpResponseExpectation.java#L272-L308","documentation":"SC_INTERNAL_SERVER_ERROR is an HttpResponseExpectation constant for HTTP 500. Vert.x applications use it with HttpClient 'expecting(...)' to assert a response is a 500 — for example HttpSendFileTest.testSendFileWithFailure expects it when sending a file that cannot be served (missing/unreadable file leads the server to fail the response with 500). It represents an unexpected server-side failure.","triggerScenarios":"Server-side failure while handling a request: in Vert.x, responding via ctx.fail(...) or an exception in a handler produces a 500. Test usage: client.request(requestOptions).compose(HttpClientRequest::send).expecting(SC_INTERNAL_SERVER_ERROR) when the send-file source file is missing so the server handler fails.","commonSituations":"Unhandled exceptions in server handlers; missing files or broken resources on the server (e.g. sendFile on a nonexistent path); NPEs from bad configuration; dependency (database/service) failures surfacing as 500.","solutions":["Inspect server logs/stack trace for the underlying exception that produced the 500 — fix the root cause, not the status.","Validate server-side inputs before failing: check file existence (vertx.fileSystem().existsBlocking) before sendFile and respond 404 instead of failing.","Wrap handler logic with error handling (ctx.fail maps to 500; use ctx.response().setStatusCode(...) for intended errors).","If testing intentional failure, keep expecting(SC_INTERNAL_SERVER_ERROR); otherwise expect SC_OK or SC_SUCCESSFUL."],"exampleFix":"// before\nctx.request().sendFile(\"missing.txt\"); // handler throws -> 500\n// after\nif (vertx.fileSystem().existsBlocking(\"missing.txt\")) {\n  ctx.request().sendFile(\"missing.txt\");\n} else {\n  ctx.response().setStatusCode(404).end();\n}","handlingStrategy":"try-catch","validationCode":"if (!vertx.fileSystem().existsBlocking(path)) {\n  throw new NoSuchFileException(path); // avoid server-side 500 from sendFile on missing file\n}","typeGuard":"boolean is500(HttpClientResponse resp) { return resp.statusCode() == 500; }","tryCatchPattern":"client.request(requestOptions)\n  .compose(HttpClientRequest::send)\n  .expecting(HttpResponseExpectation.SC_OK)\n  .onFailure(err -> { if (isCauseStatus(err, 500)) inspectServerLogsForRootCause(); });","preventionTips":["Check server-side resources (files, connections) exist before handlers use them","Respond with precise status codes (404/400) instead of ctx.fail for expected conditions","Log uncaught handler exceptions with stack traces","Cover intentional-failure paths with tests expecting 500 explicitly"],"tags":["http","server-error","sendfile","vertx-http-server"],"backgroundTag":"http-error-status","analyzedSha":"fb308bd8c3f12c79f4ae89bef67fadf6c80d036e","analyzedAt":"2026-09-06T11:37:12.241Z","contentChangedAt":"2026-09-06T11:37:12.241Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}