Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
T
tabulator-web
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
tabulator-web
Commits
8fa70004
Commit
8fa70004
authored
May 31, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add exception service
parent
10dadea5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
1 deletion
+56
-1
src/app/auth.guard.ts
src/app/auth.guard.ts
+5
-1
src/app/exception.service.spec.ts
src/app/exception.service.spec.ts
+16
-0
src/app/exception.service.ts
src/app/exception.service.ts
+34
-0
src/app/user-info.service.ts
src/app/user-info.service.ts
+1
-0
No files found.
src/app/auth.guard.ts
View file @
8fa70004
...
@@ -13,7 +13,11 @@ export class AuthGuard implements CanActivate {
...
@@ -13,7 +13,11 @@ export class AuthGuard implements CanActivate {
constructor
(
private
userInfo
:
UserInfoService
)
{}
constructor
(
private
userInfo
:
UserInfoService
)
{}
async
check
()
{
async
check
()
{
return
!!
this
.
userInfo
.
user
;
if
(
!
this
.
userInfo
.
user
)
{
this
.
userInfo
.
login
();
return
false
;
}
return
true
;
}
}
canActivate
(
route
:
ActivatedRouteSnapshot
,
state
:
RouterStateSnapshot
)
{
canActivate
(
route
:
ActivatedRouteSnapshot
,
state
:
RouterStateSnapshot
)
{
...
...
src/app/exception.service.spec.ts
0 → 100644
View file @
8fa70004
import
{
TestBed
}
from
'
@angular/core/testing
'
;
import
{
ExceptionService
}
from
'
./exception.service
'
;
describe
(
'
ExceptionService
'
,
()
=>
{
let
service
:
ExceptionService
;
beforeEach
(()
=>
{
TestBed
.
configureTestingModule
({});
service
=
TestBed
.
inject
(
ExceptionService
);
});
it
(
'
should be created
'
,
()
=>
{
expect
(
service
).
toBeTruthy
();
});
});
src/app/exception.service.ts
0 → 100644
View file @
8fa70004
import
{
Injectable
}
from
'
@angular/core
'
;
import
{
UserInfoService
}
from
'
./user-info.service
'
;
import
{
ToastService
}
from
'
./toast.service
'
;
import
{
HttpErrorResponse
}
from
'
@angular/common/http
'
;
@
Injectable
({
providedIn
:
'
root
'
,
})
export
class
ExceptionService
{
constructor
(
private
toast
:
ToastService
,
private
userInfo
:
UserInfoService
)
{}
handle
(
e
:
any
,
noRedirect
=
false
)
{
const
error
=
e
as
HttpErrorResponse
;
if
(
error
.
status
===
401
)
{
if
(
!
noRedirect
)
{
return
undefined
;
}
this
.
toast
.
warn
(
'
没有登录。
'
);
this
.
userInfo
.
login
();
}
else
{
this
.
toast
.
error
(
error
.
error
?.
message
||
error
.
message
);
}
return
undefined
;
}
async
run
<
T
>
(
fun
:
()
=>
T
|
Promise
<
T
>
):
Promise
<
T
|
undefined
>
{
try
{
return
await
fun
();
}
catch
(
e
)
{
this
.
handle
(
e
);
return
undefined
;
}
}
}
src/app/user-info.service.ts
View file @
8fa70004
...
@@ -3,6 +3,7 @@ import { MyCardSSOUser } from './utility/MyCardSSOUser';
...
@@ -3,6 +3,7 @@ import { MyCardSSOUser } from './utility/MyCardSSOUser';
import
{
ActivatedRoute
,
Router
}
from
'
@angular/router
'
;
import
{
ActivatedRoute
,
Router
}
from
'
@angular/router
'
;
import
{
loginUrl
}
from
'
./utility/login-url
'
;
import
{
loginUrl
}
from
'
./utility/login-url
'
;
import
{
Buffer
}
from
'
buffer
'
;
import
{
Buffer
}
from
'
buffer
'
;
import
{
ToastService
}
from
'
./toast.service
'
;
@
Injectable
({
@
Injectable
({
providedIn
:
'
root
'
,
providedIn
:
'
root
'
,
...
...
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