Browse Source

only return HTTP 400 on client errors

errors fetching the URL should not result in a 400 response
pull/39/head
Aaron Parecki 8 years ago
parent
commit
bf6de4de06
2 changed files with 4 additions and 4 deletions
  1. +3
    -3
      controllers/Parse.php
  2. +1
    -1
      tests/ParseTest.php

+ 3
- 3
controllers/Parse.php View File

@ -108,7 +108,7 @@ class Parse {
}
if($result['error']) {
return $this->respond($response, 400, [
return $this->respond($response, 200, [
'error' => $result['error'],
'error_description' => $result['error_description']
]);
@ -127,7 +127,7 @@ class Parse {
@$doc->loadHTML(self::toHtmlEntities($result['body']));
if(!$doc) {
return $this->respond($response, 400, [
return $this->respond($response, 200, [
'error' => 'invalid_content',
'error_description' => 'The document could not be parsed as HTML'
]);
@ -150,7 +150,7 @@ class Parse {
}
if(!$found) {
return $this->respond($response, 400, [
return $this->respond($response, 200, [
'error' => 'no_link_found',
'error_description' => 'The source document does not have a link to the target URL'
]);

+ 1
- 1
tests/ParseTest.php View File

@ -44,7 +44,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$response = $this->parse(['url' => $url, 'target' => 'http://example.net']);
$body = $response->getContent();
$this->assertEquals(400, $response->getStatusCode());
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertObjectHasAttribute('error', $data);
$this->assertEquals('no_link_found', $data->error);

Loading…
Cancel
Save