Skip to content

Commit 1cfe31d

Browse files
author
Peter Bengtsson
authored
better error handling for culprits (#68)
1 parent 75cce45 commit 1cfe31d

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

src/DeployPage.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -531,15 +531,12 @@ class ShaLink extends React.Component {
531531
}
532532
}
533533

534-
class Culprits extends React.Component {
535-
constructor(props) {
536-
super(props);
537-
this.state = {
538-
loading: true,
539-
culprits: null,
540-
error: null
541-
};
542-
}
534+
class Culprits extends React.PureComponent {
535+
state = {
536+
loading: true,
537+
culprits: null,
538+
error: null
539+
};
543540

544541
componentDidMount() {
545542
this.fetchCulprits();
@@ -550,25 +547,29 @@ class Culprits extends React.Component {
550547
this.setState({ loading: true });
551548

552549
try {
553-
const { culprits } = await ky
550+
const res = await ky
554551
.post('/culprits', { json: { owner, repo, deployments: deployInfo } })
555552
.json();
556-
this.setState({ loading: false, culprits });
553+
if (res.error) {
554+
this.setState({ error: res.error });
555+
} else {
556+
this.setState({ culprits: res.culprits });
557+
}
557558
} catch (error) {
558559
this.setState({ error });
560+
} finally {
561+
this.setState({ loading: false });
559562
}
560563
}
561564

562565
render() {
563566
const { loading, culprits, error } = this.state;
564-
565567
return (
566568
<>
567569
<h3 className="page-header culprits">Culprits</h3>
568570
{error && <div className="alert alert-danger">{error.toString()}</div>}
569-
{loading ? (
570-
'loading culprits...'
571-
) : (
571+
{loading && 'loading culprits...'}
572+
{culprits && (
572573
<div className="culprits">
573574
{culprits.map(group => (
574575
<div key={group.name} className="group">

0 commit comments

Comments
 (0)