Skip to content

Commit

Permalink
Merge pull request #128 from halprin/issue-111-error_handling
Browse files Browse the repository at this point in the history
Improve Error Handling
  • Loading branch information
halprin authored Sep 20, 2019
2 parents ff7df2d + 3ca85ed commit 7122cd2
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 16 deletions.
8 changes: 6 additions & 2 deletions backend/api/views/generic/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,13 @@ def log_response(original_function):
@wraps(original_function)
def wrapper(*args, **kwargs):
response = original_function(*args, **kwargs)
logging.info('Responding to {} with status {}'.format(original_function, response['statusCode']))
if 400 <= response['statusCode'] <= 599:
logging.warning('Response body: {}'.format(response['body']))
response_log = 'Responding to {} with status {} and body {}'.format(original_function,
response['statusCode'],
response['body'])
else:
response_log = 'Responding to {} with status {}'.format(original_function, response['statusCode'])
logging.info(response_log)
return response

return wrapper
Expand Down
12 changes: 12 additions & 0 deletions frontend/src/app/view-retro/view-retro.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ <h6 class="ml-2" *ngFor="let participant of retro?.participants">
</div>
</div>

<!--Error reporting-->
<div class="container text-center" *ngIf="errorText != ''">
<div class="row justify-content-center">
<div class="col-5">
<div class="alert alert-dismissible alert-danger">
<button type="button" class="close" (click)="hideError();">&times;</button>
{{errorText}}
</div>
</div>
</div>
</div>

<!--Initial loading spinner-->
<div class="container text-center" *ngIf="retro == null">
<div class="spinner-border" style="width: 6rem; height: 6rem;" role="status">
Expand Down
112 changes: 98 additions & 14 deletions frontend/src/app/view-retro/view-retro.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export class ViewRetroComponent implements OnInit, OnDestroy {
frontendEndpoint = environment.frontendEndpoint;
private liveUpdater: Subscription;

errorText = '';

readySpinner = false;
backSpinner = false;
forwardSpinner = false;
Expand Down Expand Up @@ -44,7 +46,9 @@ export class ViewRetroComponent implements OnInit, OnDestroy {
setupLiveUpdater() {
console.log('Setting-up the live updater');
this.liveUpdater = this.retroService.startLiveUpdateRetrospective().subscribe(messageEvent => this.retro = JSON.parse(messageEvent.data), error => {
console.error('Error on live updater');
const errorString = `Live updater failed to connect. ${JSON.stringify(error)}`;
this.errorText = errorString;
console.error(errorString);
setTimeout(() => { this.setupLiveUpdater(); }, 60000);
}, () => {
console.log('Complete live updater');
Expand All @@ -57,31 +61,60 @@ export class ViewRetroComponent implements OnInit, OnDestroy {
}

updateRetro(): void {
this.retroService.getRetrospective().subscribe(json => this.retro = json);
this.retroService.getRetrospective().subscribe(json => this.retro = json, error => {
const errorString = `Failed to get latest update of retrospective. ${JSON.stringify(error)}`;
this.errorText = errorString;
console.error(errorString);
});
}

alternateReadiness(): void {
this.readySpinner = true;
if (this.retro.yourself.ready === true) {
this.retroService.markUserAsNotReady().subscribe(() => this.readySpinner = false, () => this.readySpinner = false, () => this.readySpinner = false);
this.retroService.markUserAsNotReady().subscribe(() => this.readySpinner = false, (error) => {
this.readySpinner = false;
const errorString = `Failed to mark you as NOT ready. ${JSON.stringify(error)}`;
this.errorText = errorString;
console.error(errorString);
}, () => this.readySpinner = false);
} else {
this.retroService.markUserAsReady().subscribe(() => this.readySpinner = false, () => this.readySpinner = false, () => this.readySpinner = false);
this.retroService.markUserAsReady().subscribe(() => this.readySpinner = false, (error) => {
this.readySpinner = false;
const errorString = `Failed to mark you as ready. ${JSON.stringify(error)}`;
this.errorText = errorString;
console.error(errorString);
}, () => this.readySpinner = false);
}
}

addWentWellIssue(title: string): void {
this.addGoodIssueSpinner = true;
this.retroService.addIssue(title, 'Went Well').subscribe(() => this.addGoodIssueSpinner = false, () => this.addGoodIssueSpinner = false, () => this.addGoodIssueSpinner = false);
this.retroService.addIssue(title, 'Went Well').subscribe(() => this.addGoodIssueSpinner = false, (error) => {
this.addGoodIssueSpinner = false;
const errorString = `Failed to add a Went Well item. ${JSON.stringify(error)}`;
this.errorText = errorString;
console.error(errorString);
}, () => this.addGoodIssueSpinner = false);
}

addNeedsImprovementIssue(title: string): void {
this.addBadIssueSpinner = true;
this.retroService.addIssue(title, 'Needs Improvement').subscribe(() => this.addBadIssueSpinner = false, () => this.addBadIssueSpinner = false, () => this.addBadIssueSpinner = false);
this.retroService.addIssue(title, 'Needs Improvement').subscribe(() => this.addBadIssueSpinner = false, (error) => {
this.addBadIssueSpinner = false;
const errorString = `Failed to add a Needs Improvement issue. ${JSON.stringify(error)}`;
this.errorText = errorString;
console.error(errorString);
}, () => this.addBadIssueSpinner = false);
}

deleteIssue(issue_id: string): void {
this.deleteIssueSpinners[issue_id] = true;
this.retroService.deleteIssue(issue_id).subscribe(() => this.deleteIssueSpinners[issue_id] = false, () => this.deleteIssueSpinners[issue_id] = false, () => this.deleteIssueSpinners[issue_id] = false);
this.retroService.deleteIssue(issue_id).subscribe(() => this.deleteIssueSpinners[issue_id] = false, (error) => {
this.deleteIssueSpinners[issue_id] = false;
const errorString = `Failed to delete an issue. ${JSON.stringify(error)}`;
this.errorText = errorString;
console.error(errorString);
}, () => this.deleteIssueSpinners[issue_id] = false);
}

getWentWellIssues(): any {
Expand Down Expand Up @@ -138,12 +171,22 @@ export class ViewRetroComponent implements OnInit, OnDestroy {

moveRetroBackward(): void {
this.backSpinner = true;
this.retroService.moveRetrospectiveBackward().subscribe(() => this.backSpinner = false, () => this.backSpinner = false, () => this.backSpinner = false);
this.retroService.moveRetrospectiveBackward().subscribe(() => this.backSpinner = false, (error) => {
this.backSpinner = false;
const errorString = `Failed move retro back a step. ${JSON.stringify(error)}`;
this.errorText = errorString;
console.error(errorString);
}, () => this.backSpinner = false);
}

moveRetroForward(): void {
this.forwardSpinner = true;
this.retroService.moveRetrospectiveForward().subscribe(() => this.forwardSpinner = false, () => this.forwardSpinner = false, () => this.forwardSpinner = false);
this.retroService.moveRetrospectiveForward().subscribe(() => this.forwardSpinner = false, (error) => {
this.forwardSpinner = false;
const errorString = `Failed to move retro forward a step. ${JSON.stringify(error)}`;
this.errorText = errorString;
console.error(errorString);
}, () => this.forwardSpinner = false);
}

voteOrUnvoteForIssue(issue: any, checkbox: HTMLInputElement): void {
Expand All @@ -164,17 +207,32 @@ export class ViewRetroComponent implements OnInit, OnDestroy {

addWentWellGroup(title: string): void {
this.addGoodGroupSpinner = true;
this.retroService.addGroup(title, 'Went Well').subscribe(() => this.addGoodGroupSpinner = false, () => this.addGoodGroupSpinner = false, () => this.addGoodGroupSpinner = false);
this.retroService.addGroup(title, 'Went Well').subscribe(() => this.addGoodGroupSpinner = false, (error) => {
this.addGoodGroupSpinner = false;
const errorString = `Failed to add a Went Well group. ${JSON.stringify(error)}`;
this.errorText = errorString;
console.error(errorString);
}, () => this.addGoodGroupSpinner = false);
}

addNeedsImprovementGroup(title: string): void {
this.addBadGroupSpinner = true;
this.retroService.addGroup(title, 'Needs Improvement').subscribe(() => this.addBadGroupSpinner = false, () => this.addBadGroupSpinner = false, () => this.addBadGroupSpinner = false);
this.retroService.addGroup(title, 'Needs Improvement').subscribe(() => this.addBadGroupSpinner = false, (error) => {
this.addBadGroupSpinner = false;
const errorString = `Failed to add a Needs Improvement group. ${JSON.stringify(error)}`;
this.errorText = errorString;
console.error(errorString);
}, () => this.addBadGroupSpinner = false);
}

deleteGroup(group_id: string): void {
this.deleteGroupSpinners[group_id] = true;
this.retroService.deleteGroup(group_id).subscribe(() => this.deleteGroupSpinners[group_id] = false, () => this.deleteGroupSpinners[group_id] = false, () => this.deleteGroupSpinners[group_id] = false);
this.retroService.deleteGroup(group_id).subscribe(() => this.deleteGroupSpinners[group_id] = false, (error) => {
this.deleteGroupSpinners[group_id] = false;
const errorString = `Failed to delete a group. ${JSON.stringify(error)}`;
this.errorText = errorString;
console.error(errorString);
}, () => this.deleteGroupSpinners[group_id] = false);
}

getWentWellGroups(): any {
Expand Down Expand Up @@ -202,9 +260,19 @@ export class ViewRetroComponent implements OnInit, OnDestroy {
groupOrUngroupIssue(issue_id: string, group_id: string): void {
this.assignGroupSpinners[issue_id] = true;
if (group_id === 'ungroup') {
this.retroService.ungroupIssue(issue_id).subscribe(() => this.assignGroupSpinners[issue_id] = false, () => this.assignGroupSpinners[issue_id] = false, () => this.assignGroupSpinners[issue_id] = false);
this.retroService.ungroupIssue(issue_id).subscribe(() => this.assignGroupSpinners[issue_id] = false, (error) => {
this.assignGroupSpinners[issue_id] = false;
const errorString = `Failed to UNgroup an issue. ${JSON.stringify(error)}`;
this.errorText = errorString;
console.error(errorString);
}, () => this.assignGroupSpinners[issue_id] = false);
} else {
this.retroService.groupIssue(issue_id, group_id).subscribe(() => this.assignGroupSpinners[issue_id] = false, () => this.assignGroupSpinners[issue_id] = false, () => this.assignGroupSpinners[issue_id] = false);
this.retroService.groupIssue(issue_id, group_id).subscribe(() => this.assignGroupSpinners[issue_id] = false, (error) => {
this.assignGroupSpinners[issue_id] = false;
const errorString = `Failed to group an issue. ${JSON.stringify(error)}`;
this.errorText = errorString;
console.error(errorString);
}, () => this.assignGroupSpinners[issue_id] = false);
}
}

Expand All @@ -224,13 +292,20 @@ export class ViewRetroComponent implements OnInit, OnDestroy {
}
}

hideError(): void {
this.errorText = '';
}

private actuallyVoteForIssue(issue: any): void {
const issue_id = issue.id;
this.voteSpinners[issue_id] = true;
this.simulateVoteForIssueOrGroup(issue);
this.retroService.voteForIssue(issue_id).subscribe(response => this.voteSpinners[issue_id] = false, error => {
this.simulateUnvoteForIssueOrGroup(issue);
this.voteSpinners[issue_id] = false;
const errorString = `Failed to vote for an issue. ${JSON.stringify(error)}`;
this.errorText = errorString;
console.error(errorString);
});
}

Expand All @@ -241,6 +316,9 @@ export class ViewRetroComponent implements OnInit, OnDestroy {
this.retroService.unvoteForIssue(issue_id).subscribe(response => this.voteSpinners[issue_id] = false, error => {
this.simulateVoteForIssueOrGroup(issue);
this.voteSpinners[issue_id] = false;
const errorString = `Failed to UNvote for an issue. ${JSON.stringify(error)}`;
this.errorText = errorString;
console.error(errorString);
});
}

Expand All @@ -251,6 +329,9 @@ export class ViewRetroComponent implements OnInit, OnDestroy {
this.retroService.voteForGroup(group_id).subscribe(response => this.voteSpinners[group_id] = false, error => {
this.simulateUnvoteForIssueOrGroup(group);
this.voteSpinners[group_id] = false;
const errorString = `Failed to vote for a group. ${JSON.stringify(error)}`;
this.errorText = errorString;
console.error(errorString);
});
}

Expand All @@ -261,6 +342,9 @@ export class ViewRetroComponent implements OnInit, OnDestroy {
this.retroService.unvoteForGroup(group_id).subscribe(response => this.voteSpinners[group_id] = false, error => {
this.simulateVoteForIssueOrGroup(group);
this.voteSpinners[group_id] = false;
const errorString = `Failed to UNvote for a group. ${JSON.stringify(error)}`;
this.errorText = errorString;
console.error(errorString);
});
}

Expand Down

0 comments on commit 7122cd2

Please sign in to comment.