I’m encountering a complex issue with my Google Apps Script Web App when called from Bubble:
- Functionality:
- The script successfully creates PDFs when called.
- PDF creation works regardless of the errors encountered.
- Errors Encountered: a) Without CORS headers in the script:
- Postman: Works fine, no errors.
- Bubble: Returns a 405 Method Not Allowed error.b) With CORS headers added to the script:
- Postman: Returns an error (details below).
- Bubble: Returns the same error as Postman.
- Detailed Error Response (with CORS headers):
json
Copy
{
"body": {},
"error": {
"status_code": 200,
"status_message": "OK",
"body": "\"<!DOCTYPE html><html><head><link rel=\\\"shortcut icon\\\" href=\\\"//ssl.gstatic.com/docs/script/images/favicon.ico\\\"><title>Error</title><style type=\\\"text/css\\\" nonce=\\\"W2V97rPFRGBQWsSASeGq5g\\\">body {background-color: #fff; margin: 0; padding: 0;}.errorMessage {font-family: Arial,sans-serif; font-size: 12pt; font-weight: bold; line-height: 150%; padding-top: 25px;}</style></head><body style=\\\"margin:20px\\\"><div><img alt=\\\"Google Apps Script\\\" src=\\\"//ssl.gstatic.com/docs/script/images/logo.png\\\"></div><div style=\\\"text-align:center;font-family:monospace;margin:50px auto 0;max-width:600px\\\">Exception: The meta tag you specified is not allowed in this context. (line 60, file "Código")</div></body></html>\""
},
"returned_an_error": false,
"headers": {
"content-type": "text/html; charset=utf-8",
"cache-control": "no-cache, no-store, max-age=0, must-revalidate",
"pragma": "no-cache",
"expires": "Mon, 01 Jan 1990 00:00:00 GMT",
"date": "Thu, 15 Aug 2024 19:53:02 GMT",
"content-encoding": "gzip",
"referrer-policy": "origin",
"x-content-type-options": "nosniff",
"x-xss-protection": "1; mode=block",
"server": "GSE",
"alt-svc": "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000",
"transfer-encoding": "chunked"
}
}
- Script Setup:
- The Google Apps Script includes both doGet() and doPost() functions.
- It’s deployed as a web app with permissions set to allow access.
- Inconsistencies and Observations:
- The script creates PDFs successfully despite returning errors.
- Without CORS, Postman works fine but Bubble shows a 405 error.
- With CORS headers, both Postman and Bubble return the same error about an invalid meta tag.
- The error response has a status code of 200 (OK) but contains an HTML error message.
- The content-type header indicates HTML is being returned, not JSON as expected.
Key Questions:
- Why does adding CORS headers trigger an error about an invalid meta tag?
- How is the script processing the request and creating PDFs while simultaneously returning an HTML error page?
- Why does the response have a 200 status code when it clearly contains an error message?
- What could be causing the discrepancy between Postman and Bubble behavior without CORS headers?
- Is there a way to resolve these errors while maintaining the PDF creation functionality?
I’m particularly puzzled by the error message stating “The meta tag you specified is not allowed in this context.” This seems to be triggered by adding CORS headers, but I’m not sure why or how to resolve it.
Any insights into what might be causing this complex behavior or similar experiences would be greatly appreciated. I’m looking to understand these inconsistencies and find a way to get proper JSON responses without errors while maintaining the PDF creation functionality.