MCPcopy
hub / github.com/serverless/serverless / handleV3Error

Function handleV3Error

packages/serverless/lib/aws/v3/error-utils.js:35–87  ·  view source on GitHub ↗
(
  err,
  { serviceName, method, requestId, awsLog, log },
)

Source from the content-addressed store, hash-verified

33 name.replace(normalizerPattern, '_$1').toUpperCase()
34
35export const handleV3Error = (
36 err,
37 { serviceName, method, requestId, awsLog, log },
38) => {
39 const providerError = buildV3ProviderError(err)
40 let message = err.message || String(providerError.code)
41 if (
42 message.startsWith('Missing credentials in config') ||
43 providerError.code === 'CredentialsProviderError' ||
44 /Could not load credentials/i.test(message)
45 ) {
46 const errorMessage =
47 'AWS provider credentials not found. Learn how to set up AWS provider credentials in our docs here: http://slss.io/aws-creds-setup'
48 const wrapped = Object.assign(
49 new ServerlessError(errorMessage, 'AWS_CREDENTIALS_NOT_FOUND'),
50 { providerError: { ...providerError, retryable: false } },
51 )
52 Object.assign(wrapped, {
53 statusCode: providerError.statusCode,
54 requestId: providerError.requestId,
55 })
56 awsLog.debug(
57 `request error: #${requestId} - ${serviceName}.${method} [v3]`,
58 err,
59 )
60 if (wrapped.stack) log.debug(`${wrapped.stack}\n${'-'.repeat(100)}`)
61 throw wrapped
62 }
63 const providerErrorCodeExtension = (() => {
64 if (typeof providerError.code === 'number')
65 return `HTTP_${providerError.code}_ERROR`
66 return normalizeErrorCodePostfix(String(providerError.code || 'ERROR'))
67 })()
68 const wrapped = Object.assign(
69 new ServerlessError(
70 message,
71 `AWS_${normalizeErrorCodePostfix(serviceName)}_${normalizeErrorCodePostfix(
72 method,
73 )}_${providerErrorCodeExtension}`,
74 ),
75 { providerError },
76 )
77 Object.assign(wrapped, {
78 statusCode: providerError.statusCode,
79 requestId: providerError.requestId,
80 })
81 awsLog.debug(
82 `request error: #${requestId} - ${serviceName}.${method} [v3]`,
83 err,
84 )
85 if (wrapped.stack) log.debug(`${wrapped.stack}\n${'-'.repeat(100)}`)
86 throw wrapped
87}

Callers 1

awsRequestFunction · 0.90

Calls 3

buildV3ProviderErrorFunction · 0.85
debugMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…