Updated Error.

This commit is contained in:
cshowalter 2022-05-16 14:04:57 -07:00
parent fdd8667b64
commit 590cd0a37c
3 changed files with 24 additions and 4 deletions

View File

@ -6,7 +6,7 @@ import {
HttpInterceptor
} from '@angular/common/http';
import { catchError, Observable, throwError } from 'rxjs';
import { Router } from '@angular/router';
import { NavigationExtras, Router } from '@angular/router';
import { ToastrService } from 'ngx-toastr';
@Injectable()
@ -37,7 +37,8 @@ export class ErrorInterceptor implements HttpInterceptor {
}
if (error.status === 500){
this.router.navigateByUrl('/server-error');
const navigationExtras: NavigationExtras = {state: {error: error.error}};
this.router.navigateByUrl('/server-error', navigationExtras);
}
}
return throwError(() => new Error(error));

View File

@ -1,3 +1,17 @@
<div class="container mt-5">
<h1>Internal Server Error</h1>
<h4>Server Internal Error - Refreshing the page clears the exception</h4>
<ng-container *ngIf="e">
<h5 class="text-danger">{{e.message}}</h5>
<p class="font-weight-bold">Note: if you are seeing this, this is not a client side error.</p>
<p>What's next?</p>
<ol>
<li>Open Chrom Dev Tools</li>
<li>Inspect the Network Tab</li>
<li>Check the failing request</li>
<li>Examin the request URL. Is it correct?</li>
<li>Reproduce Error in Postman</li>
</ol>
<p>Following is the stack trace - This is where your investigation begins.</p>
<code class="mt-5" style="background-color: whitesmoke;">{{e.details}}</code>
</ng-container>
</div>

View File

@ -1,4 +1,5 @@
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
@Component({
selector: 'app-server-error',
@ -6,8 +7,12 @@ import { Component, OnInit } from '@angular/core';
styleUrls: ['./server-error.component.scss']
})
export class ServerErrorComponent implements OnInit {
e: any;
constructor() { }
constructor(private router: Router) {
const navigation = this.router.getCurrentNavigation();
this.e = navigation?.extras?.state?.error;
}
ngOnInit(): void {
}