Skip to content

Commit

Permalink
Merge pull request #258 from ibi-group/tweak-patch-error
Browse files Browse the repository at this point in the history
Change 500 error to 400 if invalid filter applied
  • Loading branch information
landonreed authored Mar 2, 2020
2 parents 423ed4d + bccb803 commit 134a323
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.conveyal.gtfs.loader.Requirement;
import com.conveyal.gtfs.loader.Table;
import com.conveyal.gtfs.model.Entity;
import com.conveyal.gtfs.storage.StorageException;
import com.conveyal.gtfs.util.InvalidNamespaceException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down Expand Up @@ -204,7 +205,11 @@ private String patchTable(Request req, Response res) {
}
for (int i = 0; i < filterFields.size(); i++) {
Field field = filterFields.get(i);
field.setParameter(preparedStatement, oneBasedIndex, filterValues.get(i));
try {
field.setParameter(preparedStatement, oneBasedIndex, filterValues.get(i));
} catch (Exception e) {
logMessageAndHalt(req, 400, "Invalid value used for field " + field.name, e);
}
oneBasedIndex++;
}
// Execute the update and commit!
Expand All @@ -216,12 +221,17 @@ private String patchTable(Request req, Response res) {
return response.toString();
} catch (HaltException e) {
throw e;
} catch (StorageException e) {
// If an invalid value was applied to a field filter, a Storage Exception will be thrown, which we should
// catch and share details with the user.
logMessageAndHalt(req, 400, "Could not patch update table", e);
} catch (Exception e) {
// This catch-all accounts for any issues encountered with SQL exceptions or other unknown issues.
logMessageAndHalt(req, 500, "Could not patch update table", e);
return null;
} finally {
DbUtils.closeQuietly(connection);
}
return null;
}

/**
Expand Down

0 comments on commit 134a323

Please sign in to comment.