From f0b01e6ebadf2d832063ef659b236ffa104f344a Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Thu, 15 Sep 2022 10:57:13 +0800 Subject: [PATCH] Improve error logging in tts cloud functions --- packages/text-to-speech/src/htmlToSsml.ts | 7 ++++++- packages/text-to-speech/src/index.ts | 14 +++++++------- packages/text-to-speech/src/textToSpeech.ts | 4 ++-- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/packages/text-to-speech/src/htmlToSsml.ts b/packages/text-to-speech/src/htmlToSsml.ts index d506f1432..8e0ec10a5 100644 --- a/packages/text-to-speech/src/htmlToSsml.ts +++ b/packages/text-to-speech/src/htmlToSsml.ts @@ -279,7 +279,12 @@ const textToUtterance = ({ try { textWithWordOffset = htmlToText(text, { wordwrap: false }) } catch (err) { - console.error('Unable to convert HTML to text', { text, err }) + console.error( + 'Unable to convert HTML to text, html:', + text, + ', error:', + err + ) textWithWordOffset = parseHTML(text).document.documentElement.textContent ?? text console.info('Converted HTML to text:', textWithWordOffset) diff --git a/packages/text-to-speech/src/index.ts b/packages/text-to-speech/src/index.ts index 643148ce9..bcc124a39 100644 --- a/packages/text-to-speech/src/index.ts +++ b/packages/text-to-speech/src/index.ts @@ -84,7 +84,7 @@ export const textToSpeechHandler = Sentry.GCPFunction.wrapHttpFunction( try { jwt.verify(token, process.env.JWT_SECRET) } catch (e) { - console.error(e) + console.error('Authentication error:', e) return res.status(200).send('UNAUTHENTICATED') } // validate input @@ -92,7 +92,7 @@ export const textToSpeechHandler = Sentry.GCPFunction.wrapHttpFunction( const id = input.id const bucket = input.bucket if (!id || !bucket) { - return res.status(200).send('Invalid data') + return res.status(200).send('INVALID_INPUT') } try { // audio file to be saved in GCS @@ -133,7 +133,7 @@ export const textToSpeechHandler = Sentry.GCPFunction.wrapHttpFunction( console.info('Text to speech cloud function completed') res.send('OK') } catch (e) { - console.error('Text to speech cloud function error', e) + console.error('Text to speech cloud function error:', e) await updateSpeech(id, token, 'FAILED') return res.status(500).send({ errorCodes: 'SYNTHESIZER_ERROR' }) } @@ -149,13 +149,13 @@ export const textToSpeechStreamingHandler = Sentry.GCPFunction.wrapHttpFunction( } const token = (req.query.token || req.headers.authorization) as string if (!token) { - return res.status(401).send({ errorCode: 'UNAUTHORIZED' }) + return res.status(401).send({ errorCode: 'INVALID_TOKEN' }) } try { jwt.verify(token, process.env.JWT_SECRET) } catch (e) { - console.error(e) - return res.status(401).send({ errorCode: 'UNAUTHORIZED' }) + console.error('Authentication error:', e) + return res.status(401).send({ errorCode: 'UNAUTHENTICATED' }) } try { @@ -174,7 +174,7 @@ export const textToSpeechStreamingHandler = Sentry.GCPFunction.wrapHttpFunction( speechMarks, }) } catch (e) { - console.error('Text to speech streaming error', e) + console.error('Text to speech streaming error:', e) return res.status(500).send({ errorCodes: 'SYNTHESIZER_ERROR' }) } } diff --git a/packages/text-to-speech/src/textToSpeech.ts b/packages/text-to-speech/src/textToSpeech.ts index 2d590bc0e..f7144d20f 100644 --- a/packages/text-to-speech/src/textToSpeech.ts +++ b/packages/text-to-speech/src/textToSpeech.ts @@ -81,7 +81,7 @@ export const synthesizeTextToSpeech = async ( if (cancellationDetails.reason === CancellationReason.Error) { str += ': ' + e.result.errorDetails } - console.error(str) + console.error('synthesis error:', str) } // The unit of e.audioOffset is tick (1 tick = 100 nanoseconds), divide by 10,000 to convert to milliseconds. @@ -157,7 +157,7 @@ export const synthesizeTextToSpeech = async ( speechMarks, } } catch (error) { - console.error('synthesis error', error) + console.error('synthesis error:', error) throw error } finally { console.log('closing synthesizer')