
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
@scriptaddicts/gas-error-handler
Advanced tools
This is a library for Google Apps Script projects. It provides methods to perform an Exponential backoff logic whenever it is needed and rewrite error objects before sending them to Stackdriver Logging.
In some cases, Google APIs can return errors on which it make sense to retry, like 'We're sorry, a server error occurred. Please wait a bit and try again.'.
In such cases, it make sense to wrap the call to the API in an Exponential backoff logic to retry multiple times.
Note that most Google Apps Script services, like GmailApp and SpreadsheetApp already have an Exponential backoff logic implemented by Google. Thus it does not make sense to wrap every call to those services in an Exponential backoff logic.
Things are different for Google Apps Script advanced services where such logic is not implemented. Thus this method is mostly useful for calls linked to Google Apps Script advanced services.
// Calls an anonymous function that gets the subject of the vacation responder in Gmail for the currently authenticated user.
var responseSubject = ErrorHandler.expBackoff(function(){return Gmail.Users.Settings.getVacation("me").responseSubject;});
| Name | Type | Description |
| Func | Function | The anonymous or named function to call. |
The value returned by the called function or nothing if the called function isn't returning anything.
This method works exactly like the fetch() method of Apps Script UrlFetchApp service.
It simply wraps the fetch() call in an Exponential backoff logic.
We advise to replace all existing calls to UrlFetchApp.fetch() by this new method.
UrlFetchApp.fetch(url, params) => ErrorHandler.urlFetchWithExpBackOff(url, params)
When exception logging is enabled, unhandled exceptions are automatically sent to Stackdriver Logging with a stack trace (see official documentation).
But if you wrap your code in a try...catch statement and use console.error(error) to send the exception to Stackdriver Logging, only the error message will be logged and not the stack trace.
We advise to replace all existing calls to console.error(error) by this new method to correctly log the stack trace, in the exact same format used for unhandled exceptions.
console.error(error) => ErrorHandler.logError(error)
| Name | Type | Description |
| e | String || Error || {lineNumber: number, fileName: string, responseCode: string} | A standard error object retrieved in a try...catch statement or created with new Error() or a simple error message or an object |
You can copy the code of this library in your own Google Apps Script project or reuse it as a standard library. In both cases, methods are called using the ErrorHandler class / namespace, meaning you will use them exactly in the same way.
To install it as a library, use the following script ID and select the latest version:
1mpYgNprGHnJW0BSPclqNIIErVaTyXQ7AjdmLaaE5O9s9bAOrsY14PMCy
To copy the code in your project, simply copy-past the content of this file in a new script file in your project:
https://github.com/RomainVialard/ErrorHandler/blob/master/src/ErrorHandler.gs.js
NPM install:
To be documented
This library contains 3 methods directly available as functions and callable without using the ErrorHandler class / namespace:
For this reason, if you copy the code in your project, make sure you don't have any other function with the exact same name.
FAQs
Methods to handle error in GAS
The npm package @scriptaddicts/gas-error-handler receives a total of 2 weekly downloads. As such, @scriptaddicts/gas-error-handler popularity was classified as not popular.
We found that @scriptaddicts/gas-error-handler demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.