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