Skip to content

Commit

Permalink
🥅 Catch API request errors
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary committed Nov 17, 2020
1 parent 4a9bb09 commit 537c4ab
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 93 deletions.
42 changes: 23 additions & 19 deletions src/components/ActiveIncidents.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import Loading from "../components/Loading.svelte";
import { onMount } from "svelte";
import config from "../data/config.json";
import { createOctokit } from "../utils/createOctokit";
import { createOctokit, handleError } from "../utils/createOctokit";
let loading = true;
const octokit = createOctokit();
Expand All @@ -11,24 +11,28 @@
let incidents = [];
onMount(async () => {
incidents = (
await octokit.issues.listForRepo({
owner,
repo,
state: "open",
filter: "all",
sort: "created",
direction: "desc",
labels: "status",
})
).data;
incidents = incidents.map((incident, index) => {
incident.showHeading =
index === 0 ||
new Date(incidents[index - 1].created_at).toLocaleDateString() !==
new Date(incident.created_at).toLocaleDateString();
return incident;
});
try {
incidents = (
await octokit.issues.listForRepo({
owner,
repo,
state: "open",
filter: "all",
sort: "created",
direction: "desc",
labels: "status",
})
).data;
incidents = incidents.map((incident, index) => {
incident.showHeading =
index === 0 ||
new Date(incidents[index - 1].created_at).toLocaleDateString() !==
new Date(incident.created_at).toLocaleDateString();
return incident;
});
} catch (error) {
handleError(error);
}
loading = false;
});
</script>
Expand Down
22 changes: 13 additions & 9 deletions src/components/Graph.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { onMount } from "svelte";
import config from "../data/config.json";
import Line from "svelte-chartjs/src/Line.svelte";
import { createOctokit } from "../utils/createOctokit";
import { createOctokit, handleError } from "../utils/createOctokit";
export let slug;
let loading = true;
Expand All @@ -15,14 +15,18 @@
let data = [];
onMount(async () => {
commits = (
await octokit.repos.listCommits({
owner,
repo,
path: `history/${slug}.yml`,
per_page: 28,
})
).data;
try {
commits = (
await octokit.repos.listCommits({
owner,
repo,
path: `history/${slug}.yml`,
per_page: 28,
})
).data;
} catch (error) {
handleError(error);
}
commits = commits.map((commit, index) => {
commit.showHeading =
index === 0 ||
Expand Down
28 changes: 16 additions & 12 deletions src/components/History.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import Loading from "../components/Loading.svelte";
import { onMount } from "svelte";
import config from "../data/config.json";
import { createOctokit } from "../utils/createOctokit";
import { createOctokit, handleError } from "../utils/createOctokit";
export let slug;
let loading = true;
Expand All @@ -12,17 +12,21 @@
let incidents = [];
onMount(async () => {
incidents = (
await octokit.issues.listForRepo({
owner,
repo,
state: "closed",
filter: "all",
sort: "created",
direction: "desc",
labels: `status,${slug}`,
})
).data;
try {
incidents = (
await octokit.issues.listForRepo({
owner,
repo,
state: "closed",
filter: "all",
sort: "created",
direction: "desc",
labels: `status,${slug}`,
})
).data;
} catch (error) {
handleError(error);
}
incidents = incidents.map((incident, index) => {
incident.showHeading =
index === 0 ||
Expand Down
42 changes: 25 additions & 17 deletions src/components/Incident.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { onMount } from "svelte";
import snarkdown from "snarkdown";
import config from "../data/config.json";
import { createOctokit } from "../utils/createOctokit";
import { createOctokit, handleError } from "../utils/createOctokit";
export let number;
Expand All @@ -18,23 +18,31 @@
let incident = {};
onMount(async () => {
incident = (
await octokit.issues.get({
owner,
repo,
issue_number: number,
sort: "created",
direction: "desc",
})
).data;
try {
incident = (
await octokit.issues.get({
owner,
repo,
issue_number: number,
sort: "created",
direction: "desc",
})
).data;
} catch (error) {
handleError(error);
}
loadingIncident = false;
comments = (
await octokit.issues.listComments({
owner,
repo,
issue_number: number,
})
).data.reverse();
try {
comments = (
await octokit.issues.listComments({
owner,
repo,
issue_number: number,
})
).data.reverse();
} catch (error) {
handleError(error);
}
loading = false;
});
</script>
Expand Down
28 changes: 16 additions & 12 deletions src/components/Incidents.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import Loading from "../components/Loading.svelte";
import { onMount } from "svelte";
import config from "../data/config.json";
import { createOctokit } from "../utils/createOctokit";
import { createOctokit, handleError } from "../utils/createOctokit";
let loading = true;
const octokit = createOctokit();
Expand All @@ -11,17 +11,21 @@
let incidents = [];
onMount(async () => {
incidents = (
await octokit.issues.listForRepo({
owner,
repo,
state: "closed",
filter: "all",
sort: "created",
direction: "desc",
labels: "status",
})
).data;
try {
incidents = (
await octokit.issues.listForRepo({
owner,
repo,
state: "closed",
filter: "all",
sort: "created",
direction: "desc",
labels: "status",
})
).data;
} catch (error) {
handleError(error);
}
incidents = incidents.map((incident, index) => {
incident.showHeading =
index === 0 ||
Expand Down
28 changes: 16 additions & 12 deletions src/components/LiveStatus.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import Loading from "../components/Loading.svelte";
import { onMount } from "svelte";
import config from "../data/config.json";
import { createOctokit } from "../utils/createOctokit";
import { createOctokit, handleError } from "../utils/createOctokit";
let loading = true;
const octokit = createOctokit();
Expand All @@ -16,17 +16,21 @@
const graphsBaseUrl = `${userContentBaseUrl}/${owner}/${repo}/master/graphs`;
onMount(async () => {
sites = JSON.parse(
atob(
(
await octokit.repos.getContent({
owner,
repo,
path: "history/summary.json",
})
).data.content.replace(/\n/g, "")
)
);
try {
sites = JSON.parse(
atob(
(
await octokit.repos.getContent({
owner,
repo,
path: "history/summary.json",
})
).data.content.replace(/\n/g, "")
)
);
} catch (error) {
handleError(error);
}
loading = false;
});
</script>
Expand Down
28 changes: 16 additions & 12 deletions src/components/Summary.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import Loading from "../components/Loading.svelte";
import { onMount } from "svelte";
import config from "../data/config.json";
import { createOctokit } from "../utils/createOctokit";
import { createOctokit, handleError } from "../utils/createOctokit";
export let slug;
let loading = true;
Expand All @@ -12,17 +12,21 @@
let summary = null;
onMount(async () => {
summary = JSON.parse(
atob(
(
await octokit.repos.getContent({
owner,
repo,
path: "history/summary.json",
})
).data.content
)
).find((item) => item.slug === slug);
try {
summary = JSON.parse(
atob(
(
await octokit.repos.getContent({
owner,
repo,
path: "history/summary.json",
})
).data.content
)
).find((item) => item.slug === slug);
} catch (error) {
handleError(error);
}
loading = false;
});
</script>
Expand Down
4 changes: 4 additions & 0 deletions src/utils/createOctokit.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ export const createOctokit = () => {
auth: token || undefined,
});
};

export const handleError = (error) => {
console.log("Error handler 123", error);
};

0 comments on commit 537c4ab

Please sign in to comment.