playframework / playframework/play1

In functional tests, unhandled exception in controller method leads to 200 response instead of 500

Open
#1,001 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
1.6k
Forks
671
Avg merge
12d 15h
Merged PRs (30d)
1

Description

When a controller method throws an unhandled exception, under normal circumstances this leads to 500 error page. However if I make request to the same method from the functional test, I get a 200 OK response.

This really breaks my functional testing, as my tests can not catch a bug which can be easily seen if opening the page manually in a browser.

To get my error I need either to use selenium test (which is slow, but it gets same result as a browser) or to wrap controller method into:

try { ... } catch (Exception ex) { error() }

In case of explicit error() call the functional test gets correct 500 return code.

I created a sample webapp, where Application.index() method throws a runtime exception and a functional test checks that its return status is 500:
https://drive.google.com/file/d/0B72ZMlJTpA1VLWxpd0lMWk5JSHM/view?usp=sharing

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the linked sample webapp, where Application.index() throws a runtime exception during a functional test. Compare the functional-test response with the browser behavior and the explicit error() case. Done when an unhandled controller exception produces a 500 status in the functional test.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend, testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.