Add Cors headers to lamda timeout so they can be detected on the FE

This commit is contained in:
Kurt Hutten
2021-06-25 19:26:33 +10:00
parent 0773915fbc
commit 87e43ab7ce
4 changed files with 33 additions and 0 deletions

View File

@@ -144,3 +144,23 @@ functions:
# NewOutput:
# Description: "Description for the output"
# Value: "Some output value"
resources:
Resources:
GatewayResponseDefault4XX:
Type: 'AWS::ApiGateway::GatewayResponse'
Properties:
ResponseParameters:
gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
gatewayresponse.header.Access-Control-Allow-Headers: "'*'"
ResponseType: DEFAULT_4XX
RestApiId:
Ref: 'ApiGatewayRestApi'
GatewayResponseDefault5XX:
Type: 'AWS::ApiGateway::GatewayResponse'
Properties:
ResponseParameters:
gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
gatewayresponse.header.Access-Control-Allow-Headers: "'*'"
ResponseType: DEFAULT_5XX
RestApiId:
Ref: 'ApiGatewayRestApi'

View File

@@ -3,6 +3,7 @@ import {
stlToGeometry,
createHealthyResponse,
createUnhealthyResponse,
timeoutErrorMessage,
} from './common'
export const render = async ({ code }) => {
@@ -29,6 +30,9 @@ export const render = async ({ code }) => {
},
}
}
if (response.status === 502) {
return createUnhealthyResponse(new Date(), timeoutErrorMessage)
}
const data = await response.json()
const geometry = await stlToGeometry(data.url)
return createHealthyResponse({

View File

@@ -38,3 +38,5 @@ export function createUnhealthyResponse(date, message = 'network issue') {
},
}
}
export const timeoutErrorMessage = `timeout: We're currently limited a 30s execution time. You can try again, sometimes it works the second time`

View File

@@ -3,6 +3,7 @@ import {
stlToGeometry,
createHealthyResponse,
createUnhealthyResponse,
timeoutErrorMessage,
} from './common'
export const render = async ({ code, settings }) => {
@@ -49,6 +50,9 @@ export const render = async ({ code, settings }) => {
const cleanedErrorMessage = cleanError(error)
return createUnhealthyResponse(new Date(), cleanedErrorMessage)
}
if (response.status === 502) {
return createUnhealthyResponse(new Date(), timeoutErrorMessage)
}
const data = await response.json()
const type = data.type !== 'stl' ? 'png' : 'geometry'
const newData = data.type !== 'stl' ? data.url : stlToGeometry(data.url)
@@ -81,6 +85,9 @@ export const stl = async ({ code, settings }) => {
const cleanedErrorMessage = cleanError(error)
return createUnhealthyResponse(new Date(), cleanedErrorMessage)
}
if (response.status === 502) {
return createUnhealthyResponse(new Date(), timeoutErrorMessage)
}
const data = await response.json()
const geometry = await stlToGeometry(data.url)
return createHealthyResponse({