import { stringify } from "querystring" ; import { GaxiosError } from "gaxios" ; export function getLogUrl ( project , functionName ) { const params = stringify ( { project , resource : `cloud_function/function_name/${ functionName }` } ) ; return `https://console.cloud.google.com/logs/viewer?${ params }` ; } export function getExecutionLogUrl ( project , functionName , executionId ) { const params = stringify ( { project , resource : `cloud_function/function_name/${ functionName }` , advancedFilter : `labels."execution_id"="${ executionId }"` } ) ; return `https://console.cloud.google.com/logs/viewer?${ params }` ; } export const httpMethodsToRetry = [ "POST" , "PUT" , "GET" , "HEAD" , "OPTIONS" , "DELETE" ] ; export const statusCodesToRetry = [ [ 100 , 199 ] , [ 429 , 429 ] , [ 405 , 405 ] , [ 500 , 599 ] ] ; param err export function shouldRetryRequest ( log ) { return ( err ) => { const config = err ?. config ?. retryConfig ; if ( ! config || config . retry === 0 ) { return false ; } if ( ! err . response && ( config . currentRetryAttempt || 0 ) >= config . noResponseRetries ! ) { return false ; } if ( err . name === "AbortError" ) { return false ; } if ( ! err . config . method || httpMethodsToRetry . indexOf ( err . config . method . toUpperCase ( ) ) < 0 ) { return false ; } if ( err . response ?. status ) { let isInRange = false ; const status = err . response . status ; for ( const [ min , max ] of statusCodesToRetry ! ) { if ( status >= min && status <= max ) { isInRange = true ; break ; } } if ( ! isInRange ) { return false ; } } config . currentRetryAttempt = config . currentRetryAttempt || 0 ; if ( config . currentRetryAttempt >= config . retry ! ) { return false ; } log ( `google: attempts: ${ config . currentRetryAttempt }/${ config . retry }, code: ${ err . code }, status: ${ err . response ?. status } name: ${ err . name }, message: ${ err . message }` ) ; return true ; } ; }