Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix UnexpectedException.getErrorDescription(): write error message in…
… any case
  • Loading branch information
asolntsev committed Jun 15, 2016
1 parent 209a5f5 commit 791a1ca
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
10 changes: 7 additions & 3 deletions framework/src/play/exceptions/UnexpectedException.java
Expand Up @@ -24,9 +24,13 @@ public String getErrorTitle() {

@Override
public String getErrorDescription() {
if (getCause() != null && getCause().getClass() != null)
return String.format("An unexpected error occurred caused by exception <strong>%s</strong>:<br/> <strong>%s</strong>", getCause().getClass().getSimpleName(), getCause().getMessage());
else return String.format("Unexpected error : %s", getMessage());
if (getCause() != null && getCause().getClass() != null) {
return String.format("Unexpected error : %s, caused by exception <strong>%s</strong>:<br/> <strong>%s</strong>",
getMessage(), getCause().getClass().getSimpleName(), getCause().getMessage());
}
else {
return String.format("Unexpected error : %s", getMessage());
}
}
}

18 changes: 18 additions & 0 deletions framework/test-src/play/exceptions/UnexpectedExceptionTest.java
@@ -0,0 +1,18 @@
package play.exceptions;

import org.junit.Test;

import static org.junit.Assert.*;

public class UnexpectedExceptionTest {
@Test
public void errorDescription_messageOnly() {
assertEquals("Unexpected error : ups", new UnexpectedException("ups").getErrorDescription());
}

@Test
public void errorDescription_messageWithCause() {
assertEquals("Unexpected error : ups, caused by exception <strong>IllegalArgumentException</strong>:<br/> <strong>forbidden</strong>",
new UnexpectedException("ups", new IllegalArgumentException("forbidden")).getErrorDescription());
}
}

0 comments on commit 791a1ca

Please sign in to comment.