Skip to content

Commit

Permalink
Merge pull request #198 from ZenAnnard/abrouwer/json_crash_fix
Browse files Browse the repository at this point in the history
Fix for a 403 error response from Nginx
  • Loading branch information
basoko authored Mar 13, 2020
2 parents 9167366 + 09865f6 commit 3197d2e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ public String toJson(Payload payload) {
@Override
public Result resultFrom(String response) {
Matcher codeMatcher = CODE_PATTERN.matcher(response);
codeMatcher.find();
if (!codeMatcher.find()) {
return new Result.Builder()
.code(1)
.body(response)
.build();
}
String codeStr = codeMatcher.group(1);
int code;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@ public class JsonSerializerImplTest {

static final String ERROR_MESSAGE = "This is the error message";

static final String UNEXPECTED_ERROR_MESSAGE = "Nobody expects the Spanish inquisition";

static final String UUID = java.util.UUID.randomUUID().toString();

static final String ERROR_RESPONSE = format("{\"err\": 1, {\"message\": \"%s\"}}",
ERROR_MESSAGE);

static final String UNEXPECTED_ERROR_RESPONSE = format("<html><body>%s</body></html>",
UNEXPECTED_ERROR_MESSAGE);

static final String SUCCESS_RESPONSE = format("{\"err\": 0, {\"uuid\": \"%s\"}}",
UUID);

Expand All @@ -32,6 +37,18 @@ public void shouldDeserializeErrorResponse() {
assertThat(sut.resultFrom(ERROR_RESPONSE), is(result));
}

@Test
public void shouldDeserializeUnexpectedErrorResponse() {
Result result = new Result.Builder()
.code(1)
.body(UNEXPECTED_ERROR_RESPONSE)
.build();

JsonSerializerImpl sut = new JsonSerializerImpl();

assertThat(sut.resultFrom(UNEXPECTED_ERROR_RESPONSE), is(result));
}

@Test
public void shouldDeserializeSuccessResponse() {
Result result = new Result.Builder()
Expand Down

0 comments on commit 3197d2e

Please sign in to comment.