Add Cors headers to lamda timeout so they can be detected on the FE
This commit is contained in:
@@ -144,3 +144,23 @@ functions:
|
|||||||
# NewOutput:
|
# NewOutput:
|
||||||
# Description: "Description for the output"
|
# Description: "Description for the output"
|
||||||
# Value: "Some output value"
|
# 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'
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import {
|
|||||||
stlToGeometry,
|
stlToGeometry,
|
||||||
createHealthyResponse,
|
createHealthyResponse,
|
||||||
createUnhealthyResponse,
|
createUnhealthyResponse,
|
||||||
|
timeoutErrorMessage,
|
||||||
} from './common'
|
} from './common'
|
||||||
|
|
||||||
export const render = async ({ code }) => {
|
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 data = await response.json()
|
||||||
const geometry = await stlToGeometry(data.url)
|
const geometry = await stlToGeometry(data.url)
|
||||||
return createHealthyResponse({
|
return createHealthyResponse({
|
||||||
|
|||||||
@@ -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`
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import {
|
|||||||
stlToGeometry,
|
stlToGeometry,
|
||||||
createHealthyResponse,
|
createHealthyResponse,
|
||||||
createUnhealthyResponse,
|
createUnhealthyResponse,
|
||||||
|
timeoutErrorMessage,
|
||||||
} from './common'
|
} from './common'
|
||||||
|
|
||||||
export const render = async ({ code, settings }) => {
|
export const render = async ({ code, settings }) => {
|
||||||
@@ -49,6 +50,9 @@ export const render = async ({ code, settings }) => {
|
|||||||
const cleanedErrorMessage = cleanError(error)
|
const cleanedErrorMessage = cleanError(error)
|
||||||
return createUnhealthyResponse(new Date(), cleanedErrorMessage)
|
return createUnhealthyResponse(new Date(), cleanedErrorMessage)
|
||||||
}
|
}
|
||||||
|
if (response.status === 502) {
|
||||||
|
return createUnhealthyResponse(new Date(), timeoutErrorMessage)
|
||||||
|
}
|
||||||
const data = await response.json()
|
const data = await response.json()
|
||||||
const type = data.type !== 'stl' ? 'png' : 'geometry'
|
const type = data.type !== 'stl' ? 'png' : 'geometry'
|
||||||
const newData = data.type !== 'stl' ? data.url : stlToGeometry(data.url)
|
const newData = data.type !== 'stl' ? data.url : stlToGeometry(data.url)
|
||||||
@@ -81,6 +85,9 @@ export const stl = async ({ code, settings }) => {
|
|||||||
const cleanedErrorMessage = cleanError(error)
|
const cleanedErrorMessage = cleanError(error)
|
||||||
return createUnhealthyResponse(new Date(), cleanedErrorMessage)
|
return createUnhealthyResponse(new Date(), cleanedErrorMessage)
|
||||||
}
|
}
|
||||||
|
if (response.status === 502) {
|
||||||
|
return createUnhealthyResponse(new Date(), timeoutErrorMessage)
|
||||||
|
}
|
||||||
const data = await response.json()
|
const data = await response.json()
|
||||||
const geometry = await stlToGeometry(data.url)
|
const geometry = await stlToGeometry(data.url)
|
||||||
return createHealthyResponse({
|
return createHealthyResponse({
|
||||||
|
|||||||
Reference in New Issue
Block a user