Redoc error handler refactor

This commit is contained in:
Roman Hotsiy 2016-10-30 17:54:44 +02:00
parent c95755718f
commit 44cd7784aa
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0
5 changed files with 36 additions and 27 deletions

View File

@ -1,15 +1,18 @@
@import url('//fonts.googleapis.com/css?family=Roboto:300,400,700');
@import url('//fonts.googleapis.com/css?family=Montserrat:400,700');
redoc.loading {
:host.loading {
position: relative;
display: block;
min-height:350px;
min-height: 350px;
}
@keyframes rotate {
0% {transform: rotate(0deg)}
100% {transform: rotate(360deg)}
0% {
transform: rotate(0deg); }
100% {
transform: rotate(360deg);
}
}
redoc.loading:before {
@ -51,20 +54,3 @@ redoc.loading:after {
redoc.loading-remove:before, redoc.loading-remove:after {
opacity: 0;
}
.redoc-error {
padding: 20px;
text-align: center;
color: #cc0000;
> h2 {
color: #cc0000;
font-size: 40px;
}
}
.redoc-error-details {
max-width: 750px;
margin: 0 auto;
font-size: 18px;
}

View File

@ -1,6 +1,6 @@
<div class="redoc-error" *ngIf="error">
<h1>Oops... ReDoc failed to render this spec</h1>
<div class='redoc-error-details'>{{_error.message}}</div>
<div class='redoc-error-details'>{{error.message}}</div>
</div>
<div class="redoc-wrap" *ngIf="specLoaded && !error">
<div class="menu-content" sticky-sidebar [scrollParent]="options.$scrollParent" [scrollYOffset]="options.scrollYOffset">

View File

@ -256,3 +256,19 @@ footer {
font-weight: bold;
}
}
.redoc-error {
padding: 20px;
text-align: center;
color: #cc0000;
> h2 {
color: #cc0000;
font-size: 40px;
}
}
.redoc-error-details {
max-width: 750px;
margin: 0 auto;
font-size: 18px;
}

View File

@ -82,8 +82,14 @@ export class Redoc extends BaseComponent implements OnInit {
ngOnInit() {
this.appState.error.subscribe(_err => {
// do not show errors that occuered after spec has been already loaded
// TODO: change this in future to show in e.g. popup
//if (this.specLoaded) return;
setTimeout(() => {
this.error = _err;
this.changeDetector.detectChanges();
this.changeDetector.detectChanges()
});
})
if (this.specUrl) {

View File

@ -2,11 +2,12 @@ import { ErrorHandler, Injectable } from '@angular/core';
import { AppStateService } from '../services/app-state.service';
@Injectable()
export class CustomErrorHandler implements ErrorHandler {
export class CustomErrorHandler extends ErrorHandler {
constructor(private appState: AppStateService) {
super(true);
}
handleError(error) {
console.log(error);
this.appState.error.next(error);
super.handleError(error);
}
}