Skip to content

Commit

Permalink
Add list of allowed methods to HttpMethodNotAllowedException
Browse files Browse the repository at this point in the history
When we know the allowed methods, add them to the exception message so
that it's easier to see what happened in error logs.
  • Loading branch information
akrabat committed Oct 3, 2019
1 parent a24fac2 commit a90e127
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions Slim/Exception/HttpMethodNotAllowedException.php
Expand Up @@ -36,6 +36,7 @@ public function getAllowedMethods(): array
public function setAllowedMethods(array $methods): HttpMethodNotAllowedException
{
$this->allowedMethods = $methods;
$this->message = 'Method not allowed. Must be one of: ' . implode(', ', $methods);
return $this;
}
}
2 changes: 2 additions & 0 deletions tests/Exception/HttpExceptionTest.php
Expand Up @@ -43,8 +43,10 @@ public function testHttpNotAllowedExceptionGetAllowedMethods()
$exception = new HttpMethodNotAllowedException($request);
$exception->setAllowedMethods(['GET']);
$this->assertEquals(['GET'], $exception->getAllowedMethods());
$this->assertEquals('Method not allowed. Must be one of: GET', $exception->getMessage());

$exception = new HttpMethodNotAllowedException($request);
$this->assertEquals([], $exception->getAllowedMethods());
$this->assertEquals('Method not allowed.', $exception->getMessage());
}
}

0 comments on commit a90e127

Please sign in to comment.