Refactor error classes; parse JSON for 5xx responses