Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
smart
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wangqinghua
smart
Commits
0a0b4632
Commit
0a0b4632
authored
Sep 17, 2019
by
wangqinghua
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
error message提示
parent
d7c91faf
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
12 deletions
+31
-12
app.module.ts
src/main/webapp/app/app.module.ts
+6
-2
auth.interceptor.ts
src/main/webapp/app/blocks/interceptor/auth.interceptor.ts
+2
-1
errorhandler.interceptor.ts
...webapp/app/blocks/interceptor/errorhandler.interceptor.ts
+23
-9
No files found.
src/main/webapp/app/app.module.ts
View file @
0a0b4632
...
@@ -31,6 +31,7 @@ import {route} from './app.route';
...
@@ -31,6 +31,7 @@ import {route} from './app.route';
import
{
LoginGuard
}
from
'./shared/common/loginGuard'
;
import
{
LoginGuard
}
from
'./shared/common/loginGuard'
;
import
{
AppMainModule
}
from
'./app.main.module'
;
import
{
AppMainModule
}
from
'./app.main.module'
;
import
{
AppService
}
from
'./app.service'
;
import
{
AppService
}
from
'./app.service'
;
import
{
NzMessageService
,
NzNotificationService
}
from
'ng-zorro-antd'
;
@
NgModule
({
@
NgModule
({
imports
:
[
imports
:
[
...
@@ -67,7 +68,8 @@ import {AppService} from './app.service';
...
@@ -67,7 +68,8 @@ import {AppService} from './app.service';
multi
:
true
,
multi
:
true
,
deps
:
[
deps
:
[
LocalStorageService
,
LocalStorageService
,
SessionStorageService
SessionStorageService
,
NzMessageService
,
]
]
},
},
{
{
...
@@ -83,7 +85,9 @@ import {AppService} from './app.service';
...
@@ -83,7 +85,9 @@ import {AppService} from './app.service';
useClass
:
ErrorHandlerInterceptor
,
useClass
:
ErrorHandlerInterceptor
,
multi
:
true
,
multi
:
true
,
deps
:
[
deps
:
[
JhiEventManager
JhiEventManager
,
NzMessageService
,
NzNotificationService
,
]
]
},
},
{
{
...
...
src/main/webapp/app/blocks/interceptor/auth.interceptor.ts
View file @
0a0b4632
...
@@ -3,13 +3,14 @@ import { LocalStorageService, SessionStorageService } from 'ngx-webstorage';
...
@@ -3,13 +3,14 @@ import { LocalStorageService, SessionStorageService } from 'ngx-webstorage';
import
{
HttpInterceptor
,
HttpRequest
,
HttpHandler
,
HttpEvent
}
from
'@angular/common/http'
;
import
{
HttpInterceptor
,
HttpRequest
,
HttpHandler
,
HttpEvent
}
from
'@angular/common/http'
;
import
{
SERVER_API_URL
}
from
'../../app.constants'
;
import
{
SERVER_API_URL
}
from
'../../app.constants'
;
import
{
ActivatedRoute
,
Router
}
from
"@angular/router"
;
import
{
ActivatedRoute
,
Router
}
from
"@angular/router"
;
import
{
NzMessageService
}
from
'ng-zorro-antd'
;
export
class
AuthInterceptor
implements
HttpInterceptor
{
export
class
AuthInterceptor
implements
HttpInterceptor
{
constructor
(
constructor
(
private
localStorage
:
LocalStorageService
,
private
localStorage
:
LocalStorageService
,
private
sessionStorage
:
SessionStorageService
,
private
sessionStorage
:
SessionStorageService
,
public
router
:
Router
,
public
router
:
Router
,
private
message
:
NzMessageService
,
)
{
)
{
}
}
...
...
src/main/webapp/app/blocks/interceptor/errorhandler.interceptor.ts
View file @
0a0b4632
import
{
JhiEventManager
}
from
'ng-jhipster'
;
import
{
JhiEventManager
}
from
'ng-jhipster'
;
import
{
HttpInterceptor
,
HttpRequest
,
HttpErrorResponse
,
HttpHandler
,
HttpEvent
}
from
'@angular/common/http'
;
import
{
HttpInterceptor
,
HttpRequest
,
HttpErrorResponse
,
HttpHandler
,
HttpEvent
}
from
'@angular/common/http'
;
import
{
Observable
}
from
'rxjs/Observable'
;
import
{
Observable
}
from
'rxjs/Observable'
;
import
'rxjs/add/operator/do'
;
import
'rxjs/add/operator/do'
;
import
{
NzMessageService
,
NzNotificationService
}
from
'ng-zorro-antd'
;
export
class
ErrorHandlerInterceptor
implements
HttpInterceptor
{
export
class
ErrorHandlerInterceptor
implements
HttpInterceptor
{
constructor
(
private
eventManager
:
JhiEventManager
)
{
constructor
(
private
eventManager
:
JhiEventManager
,
private
message
:
NzMessageService
,
public
notification
:
NzNotificationService
)
{
}
}
intercept
(
request
:
HttpRequest
<
any
>
,
next
:
HttpHandler
):
Observable
<
HttpEvent
<
any
>>
{
intercept
(
request
:
HttpRequest
<
any
>
,
next
:
HttpHandler
):
Observable
<
HttpEvent
<
any
>>
{
return
next
.
handle
(
request
).
do
((
event
:
HttpEvent
<
any
>
)
=>
{},
(
err
:
any
)
=>
{
return
next
.
handle
(
request
).
do
((
event
:
HttpEvent
<
any
>
)
=>
{
},
(
err
:
any
)
=>
{
if
(
err
instanceof
HttpErrorResponse
)
{
if
(
err
instanceof
HttpErrorResponse
)
{
if
(
!
(
err
.
status
===
401
&&
(
err
.
message
===
''
||
(
err
.
url
&&
err
.
url
.
indexOf
(
'/api/account'
)
===
0
))))
{
this
.
messageInfo
(
err
);
if
(
this
.
eventManager
!==
undefined
)
{
this
.
eventManager
.
broadcast
({
name
:
'bootappApp.httpError'
,
content
:
err
});
}
}
});
}
}
messageInfo
(
err
)
{
const
status
=
err
.
status
;
switch
(
status
)
{
case
401
:
this
.
notification
.
create
(
'error'
,
'错误'
,
'登录信息已过期'
,
{
nzDuration
:
2000
});
break
;
case
404
:
this
.
notification
.
create
(
'error'
,
'错误'
,
`
${
err
.
url
}
不存在`
,
{
nzDuration
:
2000
});
break
;
case
500
:
this
.
notification
.
create
(
'error'
,
'错误'
,
`
${
err
.
message
}
`
,
{
nzDuration
:
2000
});
break
;
}
}
});
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment