-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes for a couple exceptions caught in the logs (#77)
* do not propagate exceptions from UrlFetchAp.fetchAll for certain classes of known errors * retry api request if no response is returned after fetching * increase timeout after creating mock server again * try waiting until requests to the tunnel work * throw user friendly error message for "service invoked too many times" error from UrlFetchApp * debug build * run api.spec.ts first * remove debugging code * missing import and small refactor * small refactor to error message checking code in api.ts, add ability to mock UrlFetchApp methods during tests, and test new error message checking logic * debug test * introduce indirection to be able to mock UrlFetchApp methods * remove debugging code and a redundant if statement
- Loading branch information
Showing
10 changed files
with
345 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* Matomo - free/libre analytics platform | ||
* | ||
* @link https://matomo.org | ||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later | ||
*/ | ||
|
||
import urlFetchAppMock from './urlfetchapp-mock'; | ||
|
||
const ALL_FIXTURES = { | ||
urlfetchapp: urlFetchAppMock, | ||
}; | ||
|
||
export default ALL_FIXTURES; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* Matomo - free/libre analytics platform | ||
* | ||
* @link https://matomo.org | ||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later | ||
*/ | ||
|
||
export default function urlFetchAppMock(errorToThrow: string, throwAsString: boolean = false) { | ||
let isThrown = false; | ||
|
||
const mockUrlFetchApp = new Proxy(UrlFetchApp, { | ||
get(target, prop) { | ||
if (prop === 'fetchAll') { | ||
return function (...args) { | ||
if (!isThrown) { | ||
isThrown = true; | ||
|
||
if (throwAsString) { | ||
throw errorToThrow; | ||
} else { | ||
throw new Error(errorToThrow); | ||
} | ||
} else { | ||
return target[prop].call(this, ...args); | ||
} | ||
}; | ||
} | ||
return target[prop]; | ||
} | ||
}); | ||
|
||
return { | ||
setUp() { | ||
const getServices = (new Function('return getServices;'))(); | ||
getServices().UrlFetchApp = mockUrlFetchApp; | ||
}, | ||
tearDown() { | ||
const getServices = (new Function('return getServices;'))(); | ||
getServices().UrlFetchApp = UrlFetchApp; | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* Matomo - free/libre analytics platform | ||
* | ||
* @link https://matomo.org | ||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later | ||
*/ | ||
|
||
const SERVICES = { | ||
UrlFetchApp, | ||
}; | ||
|
||
export function getServices() { | ||
return SERVICES; | ||
} |
Oops, something went wrong.