update more checking error
This commit is contained in:
parent
8221183630
commit
edabaf7396
3 changed files with 17 additions and 6 deletions
|
|
@ -4,8 +4,9 @@ import { BrowserModule } from '@angular/platform-browser';
|
||||||
import { AppRoutingModule } from './app-routing.module';
|
import { AppRoutingModule } from './app-routing.module';
|
||||||
import { FooterComponent } from './core/layout/footer.component';
|
import { FooterComponent } from './core/layout/footer.component';
|
||||||
import { HeaderComponent } from './core/layout/header.component';
|
import { HeaderComponent } from './core/layout/header.component';
|
||||||
import { HttpClientModule } from '@angular/common/http';
|
import { HTTP_INTERCEPTORS, HttpClientModule } from '@angular/common/http';
|
||||||
import { AppComponent } from './app.component';
|
import { AppComponent } from './app.component';
|
||||||
|
import { ErrorInterceptor } from './core/interceptors/error.interceptor';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [AppComponent],
|
declarations: [AppComponent],
|
||||||
|
|
@ -16,6 +17,13 @@ import { AppComponent } from './app.component';
|
||||||
AppRoutingModule,
|
AppRoutingModule,
|
||||||
HttpClientModule,
|
HttpClientModule,
|
||||||
],
|
],
|
||||||
|
providers: [
|
||||||
|
{
|
||||||
|
provide: HTTP_INTERCEPTORS,
|
||||||
|
useClass: ErrorInterceptor,
|
||||||
|
multi: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
bootstrap: [AppComponent],
|
bootstrap: [AppComponent],
|
||||||
})
|
})
|
||||||
export class AppModule {}
|
export class AppModule {}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import {
|
||||||
} from '@angular/common/http';
|
} from '@angular/common/http';
|
||||||
import { Observable, catchError, retry, throwError } from 'rxjs';
|
import { Observable, catchError, retry, throwError } from 'rxjs';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable({ providedIn: 'root' })
|
||||||
export class ErrorInterceptor implements HttpInterceptor {
|
export class ErrorInterceptor implements HttpInterceptor {
|
||||||
constructor() {}
|
constructor() {}
|
||||||
|
|
||||||
|
|
@ -19,11 +19,7 @@ export class ErrorInterceptor implements HttpInterceptor {
|
||||||
return next.handle(request).pipe(
|
return next.handle(request).pipe(
|
||||||
catchError((error) => {
|
catchError((error) => {
|
||||||
if (error instanceof HttpErrorResponse) {
|
if (error instanceof HttpErrorResponse) {
|
||||||
if (error.status === 401) {
|
|
||||||
return next.handle(request);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return throwError(() => error);
|
return throwError(() => error);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -191,6 +191,13 @@ func (ar *AuthRouter) Route(r chi.Router) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if userInfo["error"] != nil {
|
||||||
|
w.Header().Add("Content-Type", "application/json")
|
||||||
|
w.WriteHeader(http.StatusUnauthorized)
|
||||||
|
json.NewEncoder(w).Encode(userInfo)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// return user info
|
// return user info
|
||||||
w.Header().Add("Content-Type", "application/json")
|
w.Header().Add("Content-Type", "application/json")
|
||||||
json.NewEncoder(w).Encode(map[string]interface{}{
|
json.NewEncoder(w).Encode(map[string]interface{}{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue