From 05a33190f57f8618b45d03fd3947389b29486e43 Mon Sep 17 00:00:00 2001 From: AD7six Date: Wed, 25 Sep 2013 09:20:11 +0000 Subject: [PATCH] provide a better missing error message When github say's missing, it's not talking about the resource - it means something referenced in the data. For example, specifying a milestone that doesn't exist will return: ``` { "message": "Validation Failed" "documentation_url": "http"://developer.github.com/v3" "errors": [ { "value": 42, "resource": "Issue", "field": "milestone", "code": "missing" } ] } ``` Previously this would be reported as: > Validation Failed: Resource "Issue" not exists anymore Now it's reported as > The milestone 42 doesa not exist, for resource "Issue" --- lib/Github/HttpClient/Listener/ErrorListener.php | 2 +- test/Github/Tests/HttpClient/Listener/ErrorListenerTest.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Github/HttpClient/Listener/ErrorListener.php b/lib/Github/HttpClient/Listener/ErrorListener.php index 3f20c05093b..3f2963fc995 100644 --- a/lib/Github/HttpClient/Listener/ErrorListener.php +++ b/lib/Github/HttpClient/Listener/ErrorListener.php @@ -57,7 +57,7 @@ public function postSend(RequestInterface $request, MessageInterface $response) foreach ($content['errors'] as $error) { switch ($error['code']) { case 'missing': - $errors[] = sprintf('Resource "%s" not exists anymore', $error['resource']); + $errors[] = sprintf('The %s %s does not exist, for resource "%s"', $error['field'], $error['value'], $error['resource']); break; case 'missing_field': diff --git a/test/Github/Tests/HttpClient/Listener/ErrorListenerTest.php b/test/Github/Tests/HttpClient/Listener/ErrorListenerTest.php index fb05761e891..3a539343370 100644 --- a/test/Github/Tests/HttpClient/Listener/ErrorListenerTest.php +++ b/test/Github/Tests/HttpClient/Listener/ErrorListenerTest.php @@ -124,6 +124,7 @@ public function shouldNotPassWhen422IsSentWithErrorCode($errorCode) array( 'code' => $errorCode, 'field' => 'test', + 'value' => 'wrong', 'resource' => 'fake' ) )