Skip to content

Commit baffd44

Browse files
committed
handle too many requests exception and set Retry-After header
1 parent 6f5a3ca commit baffd44

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/Dispatch/Dispatch.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,11 @@ protected function handleStatusCodeException(StatusCode\StatusCodeException $e,
133133

134134
if ($e instanceof StatusCode\MethodNotAllowedException) {
135135
$allowedMethods = $e->getAllowedMethods();
136-
137136
if (!empty($allowedMethods)) {
138137
$response->setHeader('Allow', implode(', ', $allowedMethods));
139138
}
140139
} elseif ($e instanceof StatusCode\UnauthorizedException) {
141-
$type = $e->getType();
140+
$type = $e->getType();
142141
$parameters = $e->getParameters();
143142

144143
if (!empty($type)) {
@@ -148,6 +147,11 @@ protected function handleStatusCodeException(StatusCode\StatusCodeException $e,
148147
$response->setHeader('WWW-Authenticate', $type);
149148
}
150149
}
150+
} elseif ($e instanceof StatusCode\TooManyRequestsException) {
151+
$retryAfter = $e->getRetryAfter();
152+
if ($retryAfter > 0) {
153+
$response->setHeader('Retry-After', $retryAfter);
154+
}
151155
}
152156
}
153157
}

0 commit comments

Comments
 (0)