Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Google Apps Script, how can I set the HTTP response code for a service I implement?

Say I have "service" returning a XML document:

function doGet() {
    var result = '<result>42</result>';
    var output = ContentService.createTextOutput(result);
    output.setMimeType(ContentService.MimeType.XML);
    return output;
}

By default, the HTTP status code for the response will be 200. How can I set it something different, say 500 (while still returning the same XML document)?

like image 965
avernet Avatar asked Mar 05 '13 22:03

avernet


People also ask

What is the function of a service account in a Google app script?

As defined on cloud.google.com, a service account is a special type of Google account intended to represent a non-human user that needs to authenticate and be authorized to access data in Google APIs. Typically, service accounts are used in scenarios such as: Running workloads on virtual machines (VMs).

How do I use Appscript in HTML?

To add an HTML file to your Apps Script project, open the Script Editor and choose File > New > HTML File. Within the HTML file, you can write most standard HTML, CSS, and client-side JavaScript. The page will be served as HTML5, although some advanced features of HTML5 are not available, as explained in Restrictions.


1 Answers

This is not currently possible with the ContentService. Implicitly, only the 200 status code can be returned back by the successfully completion of the script. Other error codes are all system level that get raised when something goes wrong.

If you have a good use case for this, please open a feature request in the issue tracker.

like image 90
Arun Nagarajan Avatar answered Oct 09 '22 09:10

Arun Nagarajan