Add handling for 429s from cache service
This commit is contained in:
+16
-3
@@ -1,4 +1,4 @@
|
||||
import {info, debug} from '@actions/core'
|
||||
import {info, debug, warning} from '@actions/core'
|
||||
import {getUserAgentString} from './user-agent'
|
||||
import {NetworkError, UsageError} from './errors'
|
||||
import {getCacheServiceURL} from '../config'
|
||||
@@ -109,6 +109,20 @@ class CacheServiceClient implements Rpc {
|
||||
|
||||
errorMessage = `${errorMessage}: ${body.msg}`
|
||||
}
|
||||
|
||||
// Handle rate limiting - don't retry, just warn and exit
|
||||
if (statusCode === HttpCodes.TooManyRequests) {
|
||||
const retryAfterHeader = response.message.headers['retry-after']
|
||||
if (retryAfterHeader) {
|
||||
const parsedSeconds = parseInt(retryAfterHeader, 10)
|
||||
if (!isNaN(parsedSeconds) && parsedSeconds > 0) {
|
||||
warning(
|
||||
`You've hit a rate limit, your rate limit will reset in ${parsedSeconds} seconds`
|
||||
)
|
||||
}
|
||||
}
|
||||
throw new Error(`Rate limited: ${errorMessage}`)
|
||||
}
|
||||
} catch (error) {
|
||||
if (error instanceof SyntaxError) {
|
||||
debug(`Raw Body: ${rawBody}`)
|
||||
@@ -162,8 +176,7 @@ class CacheServiceClient implements Rpc {
|
||||
HttpCodes.BadGateway,
|
||||
HttpCodes.GatewayTimeout,
|
||||
HttpCodes.InternalServerError,
|
||||
HttpCodes.ServiceUnavailable,
|
||||
HttpCodes.TooManyRequests
|
||||
HttpCodes.ServiceUnavailable
|
||||
]
|
||||
|
||||
return retryableStatusCodes.includes(statusCode)
|
||||
|
||||
Reference in New Issue
Block a user