hackforla / hackforla/website

Add error handling to `get-timeline.js`

Open
#7,105 1 comment 0 reactions 0 assignees View on GitHub
Complexity: Missing Complexity: Small Feature: Refactor JS / Liquid role: back end/devOps size: 1pt
Dominant language
JavaScript
Stars
363
Forks
872
Avg merge
2d 21h
Merged PRs (30d)
18

Description

## Note
- Keeping this in the "Ice Box" but I believe this is something we **_do not want to do_**.
- The argument for adding error handling: the workflow can run to completion despite an error occurring.
- The argument against adding error handling: since the workflow completes without interruption, and the workflow logs will show Green. Without reading through the workflow logs or seeing obvious failures you will not know that an error is occurring.***
- On the other hand, without error handling the workflow crashes and the workflow logs show Red. I feel that this is a preferable outcome because it is obvious that something occurred.

*** But we could create a centralized log that sends an alert if an error occurs. But do we need this?

### Overview
In some instances when an error occurs during a workflow run, we want the workflow to retry a number of times and if the error still occurs to appropriately log the error- but continue running to completion. We want to add error handling and retries to the `get-timeline.js` so that the workflow is not stopped prematurely, but still logs the error.

### Action Items
Refer to [get-timeline.js](https://github.com/hackforla/website/blob/gh-pages/github-actions/utils/get-timeline.js):
- [ ] After `} catch (err) {` starting on line 26 replace:

```
console.log(err);
continue;
} finally {
page++;
```
with:
```
if (err instanceof TypeError) throw new Error(err);
if (retries < maxRetries) {
const delay = Math.pow(2, retries);
console.log(`Retrying in ${delay} seconds...`);
await new Promise(resolve => setTimeout(resolve, delay * 1000));
retries++;
} else {
console.error(err);
throw new Error(`Failed to fetch timeline for issue #${issue_number}`);
}
```
- [ ] After defining `timelineArray` on line 21, insert a new line:

```
page++;
```
- [ ] At line 10, replace:

```
let page = 1;
```
with:

```
let page = 1; retries = 0;
const per_page = 100, maxRetries = 3;
```
- [ ] After line 2 insert a new line with the url to the GitHub API:

```
* https://octokit.github.io/rest.js/v20#issues-list-events-for-timeline
```
- [ ] The changes to this function need to be tested to confirm that
### Resources/Instructions
- This issue was initiated by ER #6840

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.