Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
foreign
/
customer-service
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
77a09347
authored
Dec 31, 2021
by
Sixong.Zhu
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
update monitor
parent
0e5692b2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
115 additions
and
0 deletions
service/monitor.ts
service/monitor.ts
0 → 100644
View file @
77a09347
import
Axios
from
"axios"
;
import
{
UniplatSdk
}
from
"uniplat-sdk"
;
import
{
ImEnvironment
}
from
"../model"
;
export
const
enum
Product
{
Default
=
'default'
,
QqxbWeixin
=
'qqxb-weixin'
,
QqxbApp
=
'qqxb-app'
,
Fulibao
=
'fulibao'
,
HrManager
=
'hr-manager'
,
Hrs100
=
'hrs100'
,
HrsApp
=
'hrs-app'
,
BiJie
=
'bi-jie'
,
Cashier
=
'cashier'
,
Uniplat
=
"uniplat"
,
}
const
enum
ProductTable
{
Default
=
""
,
Login
=
"login"
,
Error
=
"error"
,
}
export
interface
SdkMonitorOption
{
userAgent
?:
boolean
;
envir
:
ImEnvironment
;
product
:
Product
;
}
class
WebMonitor
{
private
key
=
""
;
private
envir
=
ImEnvironment
.
Dev
;
private
product
=
Product
.
Default
;
private
readonly
url
=
"https://pre-hrs-monitor.hrs100.com"
;
public
updateKey
(
key
:
string
)
{
this
.
key
=
key
;
return
this
;
}
private
buildHeaders
()
{
return
{
headers
:
{
authorization
:
"cdd0a34e-f537-4e5b-808e-2ba06af21845"
},
};
}
private
enable
()
{
return
this
.
envir
===
ImEnvironment
.
Dev
;
}
private
envirString
()
{
if
(
this
.
envir
===
ImEnvironment
.
Dev
)
{
return
"[Dev]"
;
}
if
(
this
.
envir
===
ImEnvironment
.
Stage
)
{
return
"[Stage]"
;
}
return
""
;
}
public
log
(
msg
:
any
)
{
return
Axios
.
post
(
this
.
url
,
{
type
:
ProductTable
.
Login
,
product
:
this
.
product
,
msg
:
`
${
this
.
envirString
()}
${
msg
}
`
,
key
:
this
.
key
,
},
this
.
buildHeaders
()
);
}
public
error
(
msg
:
any
)
{
return
Axios
.
post
(
this
.
url
,
{
type
:
ProductTable
.
Error
,
product
:
this
.
product
,
msg
:
`
${
this
.
envirString
()}
${
msg
}
`
,
key
:
this
.
key
,
},
this
.
buildHeaders
()
);
}
public
useSdk
(
sdk
:
UniplatSdk
,
options
:
SdkMonitorOption
)
{
this
.
envir
=
options
.
envir
;
this
.
product
=
options
.
product
;
sdk
.
events
.
addUniversalErrorResponseCallback
((
r
)
=>
{
if
(
this
.
enable
())
{
const
msg
:
string
[]
=
[];
msg
.
push
(
`URL:
${
decodeURIComponent
(
r
.
config
.
url
)}
`
);
msg
.
push
(
`Token:
${
sdk
.
global
.
jwtToken
}
`
);
const
header
=
r
.
config
.
headers
;
if
(
header
)
{
msg
.
push
(
`CurrentOrg:
${
header
.
CurrentOrg
}
`
);
msg
.
push
(
`Scenes:
${
header
.
Scenes
}
`
);
}
msg
.
push
(
`Exception:
${((
r
.
data
.
error
as
string
)
||
""
).
substring
(
0
,
500
)}
`
);
options
&&
options
.
userAgent
&&
msg
.
push
(
`UserAgent:
${
window
.
navigator
.
userAgent
}
`
);
r
&&
r
.
config
&&
this
.
error
(
msg
.
join
(
"\n"
));
}
});
}
}
export
const
monitor
=
new
WebMonitor
();
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