Google Apps Script Web App returns errors but still creates PDFs - CORS issues and inconsistent behavior

I’m encountering a complex issue with my Google Apps Script Web App when called from Bubble:

  1. Functionality:
  • The script successfully creates PDFs when called.
  • PDF creation works regardless of the errors encountered.
  1. 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.
  1. 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 &quot;Código&quot;)</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"
  }
}
  1. 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.
  1. 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:

  1. Why does adding CORS headers trigger an error about an invalid meta tag?
  2. How is the script processing the request and creating PDFs while simultaneously returning an HTML error page?
  3. Why does the response have a 200 status code when it clearly contains an error message?
  4. What could be causing the discrepancy between Postman and Bubble behavior without CORS headers?
  5. 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.

Are you calling script client side?
I guess the 200 status you get is because you don’t use the correct request (POST/GET…) or wrong url endpoint (Almost sure it’s when you do a get request…)

A little bit hard to debug without all information about the request you are doing…

Hello Jici,

Thank you for your quick response. I apologize for not providing more details initially; I wanted to avoid overwhelming the post. Let me provide some additional information that might help clarify the situation.

  1. Bubble API Configuration:


This is an example of my Bubble API configuration. I’ve altered parts of the URL for privacy, but the structure remains the same.
2. CORS and Script Behavior: I suspect CORS might be involved, but interestingly, when CORS headers are implemented in the Google Apps Script, it returns a failure response yet still successfully generates the PDF. This inconsistent behavior is puzzling.
3. Google Apps Script: If it would be helpful, I can share the relevant parts of my Google Apps Script. The script includes both doGet() and doPost() functions and is deployed as a web app with appropriate permissions.
4. Process Flow: The entire process works fine in isolation. The error only occurs when initiating the call from Bubble, yet the desired action (PDF generation) still completes successfully.
5. Similar Issue: I found a StackOverflow post that seems to describe a similar problem, but I couldn’t resolve my issue based on the solutions provided there: [Google Apps Script return 405 for POST request]

I appreciate any insights or suggestions you might have regarding these issues. If you need any specific parts of the Google Apps Script or additional information, please let me know, and I’ll be happy to provide them.

Thanks

This topic was automatically closed after 70 days. New replies are no longer allowed.