Fix console error messages
This commit is contained in:
@@ -20,8 +20,12 @@ const makeRequest = (route, port) => [
|
|||||||
})
|
})
|
||||||
res.status(data.statusCode)
|
res.status(data.statusCode)
|
||||||
res.setHeader('Content-Type', 'application/javascript')
|
res.setHeader('Content-Type', 'application/javascript')
|
||||||
res.setHeader('Content-Encoding', 'gzip')
|
if (data.headers && data.headers['Content-Encoding'] === 'gzip') {
|
||||||
res.send(Buffer.from(data.body, 'base64'))
|
res.setHeader('Content-Encoding', 'gzip')
|
||||||
|
res.send(Buffer.from(data.body, 'base64'))
|
||||||
|
} else {
|
||||||
|
res.send(Buffer.from(data.body, 'base64'))
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
res.status(500)
|
res.status(500)
|
||||||
res.send()
|
res.send()
|
||||||
|
|||||||
@@ -19,9 +19,9 @@ export const runCQ = async ({
|
|||||||
`--outputopts "deflection:${deflection};angularDeflection:${deflection};"`,
|
`--outputopts "deflection:${deflection};angularDeflection:${deflection};"`,
|
||||||
].join(' ')
|
].join(' ')
|
||||||
console.log('command', command)
|
console.log('command', command)
|
||||||
|
let consoleMessage = ''
|
||||||
try {
|
try {
|
||||||
const consoleMessage = await runCommand(command, 30000)
|
consoleMessage = await runCommand(command, 30000)
|
||||||
await writeFiles(
|
await writeFiles(
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
@@ -36,10 +36,10 @@ export const runCQ = async ({
|
|||||||
)
|
)
|
||||||
await runCommand(
|
await runCommand(
|
||||||
`cat ${stlPath} /var/task/cadhub-concat-split /tmp/${tempFile}/metadata.json | gzip > ${fullPath}`,
|
`cat ${stlPath} /var/task/cadhub-concat-split /tmp/${tempFile}/metadata.json | gzip > ${fullPath}`,
|
||||||
15000
|
15000, true
|
||||||
)
|
)
|
||||||
return { consoleMessage, fullPath }
|
return { consoleMessage, fullPath }
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return { error, fullPath }
|
return { error: consoleMessage, fullPath }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ export async function writeFiles(
|
|||||||
return tempFile
|
return tempFile
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function runCommand(command, timeout = 5000): Promise<string> {
|
export async function runCommand(command, timeout = 5000, shouldRejectStdErr = false): Promise<string> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
exec(command, (error, stdout, stderr) => {
|
exec(command, (error, stdout, stderr) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
@@ -35,6 +35,10 @@ export async function runCommand(command, timeout = 5000): Promise<string> {
|
|||||||
}
|
}
|
||||||
if (stderr) {
|
if (stderr) {
|
||||||
console.log(`stderr: ${stderr}`)
|
console.log(`stderr: ${stderr}`)
|
||||||
|
if (shouldRejectStdErr) {
|
||||||
|
reject(stderr)
|
||||||
|
return
|
||||||
|
}
|
||||||
resolve(stderr)
|
resolve(stderr)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -105,7 +109,8 @@ export async function storeAssetAndReturnUrl({
|
|||||||
if (error) {
|
if (error) {
|
||||||
const response = {
|
const response = {
|
||||||
statusCode: 400,
|
statusCode: 400,
|
||||||
body: JSON.stringify({ error, fullPath }),
|
body: Buffer.from(JSON.stringify({ error, fullPath })).toString('base64'),
|
||||||
|
isBase64Encoded: true,
|
||||||
}
|
}
|
||||||
callback(null, response)
|
callback(null, response)
|
||||||
return
|
return
|
||||||
@@ -119,7 +124,8 @@ export async function storeAssetAndReturnUrl({
|
|||||||
console.log('read file error', e)
|
console.log('read file error', e)
|
||||||
const response = {
|
const response = {
|
||||||
statusCode: 400,
|
statusCode: 400,
|
||||||
body: JSON.stringify({ error: consoleMessage, fullPath }),
|
body: Buffer.from(JSON.stringify({ error: consoleMessage, fullPath })).toString('base64'),
|
||||||
|
isBase64Encoded: true,
|
||||||
}
|
}
|
||||||
callback(null, response)
|
callback(null, response)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -43,13 +43,10 @@ export const render: DefaultKernelExport['render'] = async ({
|
|||||||
}
|
}
|
||||||
const blob = await response.blob()
|
const blob = await response.blob()
|
||||||
const text = await new Response(blob).text()
|
const text = await new Response(blob).text()
|
||||||
const { consoleMessage, customizerParams, type } = splitGziped(text)
|
const { consoleMessage } = splitGziped(text)
|
||||||
return createHealthyResponse({
|
return createHealthyResponse({
|
||||||
type: type !== 'stl' ? 'png' : 'geometry',
|
type: 'geometry',
|
||||||
data:
|
data: await stlToGeometry(window.URL.createObjectURL(blob)),
|
||||||
type !== 'stl'
|
|
||||||
? blob
|
|
||||||
: await stlToGeometry(window.URL.createObjectURL(blob)),
|
|
||||||
consoleMessage,
|
consoleMessage,
|
||||||
date: new Date(),
|
date: new Date(),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { CadhubParams } from 'src/components/Customizer/customizerConverter'
|
|||||||
|
|
||||||
export const lambdaBaseURL =
|
export const lambdaBaseURL =
|
||||||
process.env.CAD_LAMBDA_BASE_URL ||
|
process.env.CAD_LAMBDA_BASE_URL ||
|
||||||
'https://2inlbple1b.execute-api.us-east-1.amazonaws.com/prod2'
|
'https://oxt2p7ddgj.execute-api.us-east-1.amazonaws.com/prod'
|
||||||
|
|
||||||
export const stlToGeometry = (url) =>
|
export const stlToGeometry = (url) =>
|
||||||
new Promise((resolve, reject) => {
|
new Promise((resolve, reject) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user