Skip to content

Commit

Permalink
Added Error Response Handling fixed #9
Browse files Browse the repository at this point in the history
  • Loading branch information
pishangujeniya committed Nov 23, 2022
1 parent 6d56990 commit 1981cfb
Show file tree
Hide file tree
Showing 22 changed files with 231 additions and 53 deletions.
4 changes: 2 additions & 2 deletions src/KiteHelper/ClientApp/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/KiteHelper/ClientApp/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kitehelper",
"version": "1.0",
"version": "1.1",
"scripts": {
"postinstall": "ngcc --properties es2015 es5 browser module main --first-only --create-ivy-entry-points",
"install:packages": "npm install --legacy-peer-deps --location=project",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { HttpResponse, HttpErrorResponse } from '@angular/common/http';
import { Component, OnDestroy, OnInit } from '@angular/core';
import { NbMenuService, NbSidebarService, NbToastrService } from '@nebular/theme';
import { NbDialogService, NbMenuService, NbSidebarService, NbToastrService } from '@nebular/theme';

import { Subject } from 'rxjs';
import { KiteApiService, ProfileResponseModel } from 'src/app/services/api/kite-api.service';
import { RoutingHelperService } from 'src/app/services/routing-helper.service';
import { ErrorDialogComponent } from 'src/app/shared/error-dialog/error-dialog.component';
import { environment } from 'src/environments/environment';

@Component({
Expand Down Expand Up @@ -34,6 +35,7 @@ export class HeaderComponent implements OnInit, OnDestroy {
private hamburgerService: NbMenuService,
private toastrService: NbToastrService,
private kiteApiService: KiteApiService,
private dialogService: NbDialogService,
) { }

ngOnInit() {
Expand All @@ -51,7 +53,15 @@ export class HeaderComponent implements OnInit, OnDestroy {
}, (errorResponse: HttpErrorResponse) => {
console.error(errorResponse);
if (errorResponse.status > 0) {
this.toastrService.danger(JSON.stringify(errorResponse.error), environment.defaultErrorTitle);
this.toastrService.danger(JSON.stringify(errorResponse.error), environment.defaultErrorTitle, { duration: 5000 });
this.dialogService.open(ErrorDialogComponent,
{
hasBackdrop: true,
context: {
errorTitle: environment.defaultErrorTitle,
errorMessage: JSON.stringify(errorResponse.error),
},
});
} else {
this.toastrService.danger(environment.defaultErrorMessage, environment.defaultErrorTitle);
}
Expand Down
3 changes: 3 additions & 0 deletions src/KiteHelper/ClientApp/src/app/account/account.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
NbButtonModule,
NbCardModule,
NbCheckboxModule,
NbDialogService,
NbIconModule,
NbInputModule,
NbLayoutModule,
Expand All @@ -21,6 +22,7 @@ import { FormsModule } from '@angular/forms';
import { RouterModule } from '@angular/router';
import { NbAuthModule } from '@nebular/auth';
import { LogoutComponent } from './logout/logout.component';
import { SharedModule } from '../shared/shared.module';

@NgModule({
declarations: [
Expand All @@ -45,6 +47,7 @@ import { LogoutComponent } from './logout/logout.component';
NbAuthModule,
NbTooltipModule,
NbToastrModule,
SharedModule,
],
})
export class AccountModule { }
14 changes: 12 additions & 2 deletions src/KiteHelper/ClientApp/src/app/account/login/login.component.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { HttpErrorResponse, HttpResponse } from '@angular/common/http';
import { Component, OnInit } from '@angular/core';
import { NbToastrService } from '@nebular/theme';
import { NbDialogService, NbToastrService } from '@nebular/theme';
import { KiteApiService, KiteLoginResponseModel } from 'src/app/services/api/kite-api.service';
import { CookieHelperService } from 'src/app/services/cookie-helper.service';
import { RoutingHelperService } from 'src/app/services/routing-helper.service';
import { ErrorDialogComponent } from 'src/app/shared/error-dialog/error-dialog.component';
import { environment } from 'src/environments/environment';

class UserNgModel {
Expand All @@ -26,6 +27,7 @@ export class LoginComponent implements OnInit {
private toastrService: NbToastrService,
private routingService: RoutingHelperService,
private kiteApiService: KiteApiService,
private dialogService: NbDialogService,
) {
}

Expand All @@ -52,7 +54,15 @@ export class LoginComponent implements OnInit {
}, (errorResponse: HttpErrorResponse) => {
console.error(errorResponse);
if (errorResponse.status > 0) {
this.toastrService.danger(JSON.stringify(errorResponse.error), environment.defaultErrorTitle);
this.toastrService.danger(JSON.stringify(errorResponse.error), environment.defaultErrorTitle, { duration: 5000 });
this.dialogService.open(ErrorDialogComponent,
{
hasBackdrop: true,
context: {
errorTitle: environment.defaultErrorTitle,
errorMessage: JSON.stringify(errorResponse.error),
},
});
} else {
this.toastrService.danger(environment.defaultErrorMessage, environment.defaultErrorTitle);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { RouterModule, Routes } from '@angular/router';
import { Component, NgModule } from '@angular/core';

import { DashboardComponent } from './dashboard.component';
import { NotFoundComponent } from './shared/not-found/not-found.component';
import { NotFoundComponent } from '../shared/not-found/not-found.component';

const routes: Routes = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { NbCardModule, NbIconModule, NbMenuModule, NbSpinnerModule } from '@nebu
import { ThemeModule } from '../@theme/theme.module';
import { DashboardComponent } from './dashboard.component';
import { DashboardRoutingModule } from './dashboard-routing.module';
import { SharedModule } from './shared/shared.module';
import { SharedModule } from '../shared/shared.module';


@NgModule({
Expand All @@ -16,7 +16,6 @@ import { SharedModule } from './shared/shared.module';
NbCardModule,
NbIconModule,
NbSpinnerModule,
SharedModule,
],
declarations: [
DashboardComponent,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { HttpErrorResponse, HttpResponse } from '@angular/common/http';
import { Component, Input, OnInit } from '@angular/core';
import { NbDialogRef, NbToastrService } from '@nebular/theme';
import { NbDialogRef, NbDialogService, NbToastrService } from '@nebular/theme';
import { HistoricalDataResponseModel, KiteApiService, TradingSymbolResponseModel } from 'src/app/services/api/kite-api.service';
import { HelperService } from 'src/app/services/helper.service';
import { ErrorDialogComponent } from 'src/app/shared/error-dialog/error-dialog.component';
import { environment } from 'src/environments/environment';

@Component({
Expand All @@ -27,6 +28,7 @@ export class DownloadHistoricalDataComponent implements OnInit {
private toastrService: NbToastrService,
private helperService: HelperService,
private dialogRef: NbDialogRef<DownloadHistoricalDataComponent>,
private dialogService: NbDialogService,
) {
}

Expand Down Expand Up @@ -59,7 +61,15 @@ export class DownloadHistoricalDataComponent implements OnInit {
}, (errorResponse: HttpErrorResponse) => {
console.error(errorResponse);
if (errorResponse.status > 0) {
this.toastrService.danger(JSON.stringify(errorResponse.error), environment.defaultErrorTitle);
this.toastrService.danger(JSON.stringify(errorResponse.error), environment.defaultErrorTitle, { duration: 5000 });
this.dialogService.open(ErrorDialogComponent,
{
hasBackdrop: true,
context: {
errorTitle: environment.defaultErrorTitle,
errorMessage: JSON.stringify(errorResponse.error),
},
});
} else {
this.toastrService.danger(environment.defaultErrorMessage, environment.defaultErrorTitle);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { HttpErrorResponse, HttpResponse } from '@angular/common/http';
import { Component, OnInit, ViewChild } from '@angular/core';
import { NbDialogService, NbToastrService } from '@nebular/theme';
import { KiteApiService, TradingSymbolResponseModel } from 'src/app/services/api/kite-api.service';
import { ErrorDialogComponent } from 'src/app/shared/error-dialog/error-dialog.component';
import { environment } from 'src/environments/environment';
import { DownloadHistoricalDataComponent } from '../download-historical-data/download-historical-data.component';

Expand Down Expand Up @@ -48,7 +49,15 @@ export class HistoricalDataComponent implements OnInit {
}, (errorResponse: HttpErrorResponse) => {
console.error(errorResponse);
if (errorResponse.status > 0) {
this.toastrService.danger(JSON.stringify(errorResponse.error), environment.defaultErrorTitle);
this.toastrService.danger(JSON.stringify(errorResponse.error), environment.defaultErrorTitle, { duration: 5000 });
this.dialogService.open(ErrorDialogComponent,
{
hasBackdrop: true,
context: {
errorTitle: environment.defaultErrorTitle,
errorMessage: JSON.stringify(errorResponse.error),
},
});
} else {
this.toastrService.danger(environment.defaultErrorMessage, environment.defaultErrorTitle);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { HistoricalDataComponent } from './historical-data/historical-data.compo
import { HistoricalComponent } from './historical.component';
import { NbAutocompleteModule, NbButtonModule, NbCardModule, NbDatepickerModule, NbDialogModule, NbIconModule, NbInputModule, NbRadioModule, NbSpinnerModule, NbTimepickerModule } from '@nebular/theme';
import { FormsModule } from '@angular/forms';
import { SharedModule } from '../shared/shared.module';
import { SharedModule } from '../../shared/shared.module';
import { DownloadHistoricalDataComponent } from './download-historical-data/download-historical-data.component';


Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<nb-card>
<nb-card-header>
<div class="row">
<div class="col-lg-12">
{{errorTitle}}
</div>
</div>
</nb-card-header>
<nb-card-body>

<div class="row">
<div class="col-lg-12">
<label class="label" for="error-message">Message:</label>
<p style="color: red;" id="error-message">{{errorMessage}}</p>
</div>
</div>
</nb-card-body>
<nb-card-footer>
<div class="row">
<div class="col-lg-12">
<button nbButton fullWidth status="warning" size="large" (click)="copyToClipboard();">
<nb-icon icon="copy-outline"></nb-icon>
Copy Message
</button>
</div>
</div>
</nb-card-footer>
</nb-card>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Component, Input, OnInit } from '@angular/core';
import { Clipboard } from '@angular/cdk/clipboard';

@Component({
selector: 'app-error-dialog',
templateUrl: './error-dialog.component.html',
styleUrls: ['./error-dialog.component.css'],
})
export class ErrorDialogComponent implements OnInit {

@Input() public errorTitle: string;
@Input() public errorMessage: string;

constructor(private clipboard: Clipboard) { }

ngOnInit(): void {
}

copyToClipboard(): void {
this.clipboard.copy(this.errorMessage);
}

}
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { NotFoundComponent } from './not-found/not-found.component';
import { NbAlertModule, NbButtonModule, NbCardModule, NbProgressBarModule, NbSpinnerModule } from '@nebular/theme';
import { NbAlertModule, NbButtonModule, NbCardModule, NbIconModule, NbProgressBarModule, NbSpinnerModule } from '@nebular/theme';
import { TradingSymbolComponent } from './trading-symbol/trading-symbol.component';
import { ErrorDialogComponent } from './error-dialog/error-dialog.component';


@NgModule({
declarations: [NotFoundComponent, TradingSymbolComponent],
declarations: [NotFoundComponent, TradingSymbolComponent, ErrorDialogComponent],
imports: [
CommonModule,
NbCardModule,
NbButtonModule,
NbAlertModule,
NbSpinnerModule,
NbProgressBarModule,
NbIconModule
],
exports: [
NotFoundComponent,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import "../../../@theme/styles/themes";
@import "../../@theme/styles/themes";

@include nb-install-component() {
.trading-symbol {
Expand Down
Loading

0 comments on commit 1981cfb

Please sign in to comment.