From bf6de4de0667647020d00ad0d494751862405691 Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Sat, 5 Mar 2016 12:20:38 -0800 Subject: [PATCH] only return HTTP 400 on client errors errors fetching the URL should not result in a 400 response --- controllers/Parse.php | 6 +++--- tests/ParseTest.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/controllers/Parse.php b/controllers/Parse.php index 3701005..2b627d3 100644 --- a/controllers/Parse.php +++ b/controllers/Parse.php @@ -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' ]); diff --git a/tests/ParseTest.php b/tests/ParseTest.php index 362f03b..1867485 100644 --- a/tests/ParseTest.php +++ b/tests/ParseTest.php @@ -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);