Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
C
chatGLM
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
1
Merge Requests
1
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
刘坚-丰林-DEV
chatGLM
Commits
a95cf7e2
Commit
a95cf7e2
authored
Apr 16, 2023
by
Ylg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add request interceptors
parent
35cb260a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
5 deletions
+14
-5
api.ts
src/services/chatGLM/api.ts
+14
-5
No files found.
src/services/chatGLM/api.ts
View file @
a95cf7e2
...
@@ -8,6 +8,20 @@ interface ILoginParams {
...
@@ -8,6 +8,20 @@ interface ILoginParams {
const
request
=
extend
({});
const
request
=
extend
({});
request
.
interceptors
.
request
.
use
((
url
,
options
)
=>
{
const
token
=
JSON
.
parse
(
localStorage
.
getItem
(
'user'
))?.
token
;
const
authHeader
=
{
Authorization
:
`Bearer
${
token
||
''
}
`
,
'Content-Type'
:
'application/json'
,
'__tenant'
:
'3a0a90fe-9a0d-70f4-200d-a80a41fb6195'
};
return
{
url
:
url
,
options
:
{
...
options
,
interceptors
:
true
,
headers
:
authHeader
},
};
});
request
.
interceptors
.
response
.
use
(
async
(
response
):
Promise
<
any
>
=>
{
request
.
interceptors
.
response
.
use
(
async
(
response
):
Promise
<
any
>
=>
{
console
.
log
(
'response'
,
response
);
console
.
log
(
'response'
,
response
);
if
(
response
.
status
===
401
)
{
if
(
response
.
status
===
401
)
{
...
@@ -23,10 +37,6 @@ request.interceptors.response.use(async (response): Promise<any> => {
...
@@ -23,10 +37,6 @@ request.interceptors.response.use(async (response): Promise<any> => {
export
function
loginChatGLM
(
options
:
ILoginParams
)
{
export
function
loginChatGLM
(
options
:
ILoginParams
)
{
return
request
(
'https://glm-mangement-api.baibaomen.com/api/app/account/login'
,
{
return
request
(
'https://glm-mangement-api.baibaomen.com/api/app/account/login'
,
{
method
:
'POST'
,
method
:
'POST'
,
headers
:
{
'Content-Type'
:
'application/json'
,
__tenant
:
'3a0a90fe-9a0d-70f4-200d-a80a41fb6195'
,
},
data
:
options
,
data
:
options
,
});
});
}
}
...
@@ -34,6 +44,5 @@ export function loginChatGLM(options: ILoginParams) {
...
@@ -34,6 +44,5 @@ export function loginChatGLM(options: ILoginParams) {
export
function
GetChatGLMToken
():
Promise
<
string
>
{
export
function
GetChatGLMToken
():
Promise
<
string
>
{
return
request
(
'https://glm-mangement-api.baibaomen.com/user/token'
,
{
return
request
(
'https://glm-mangement-api.baibaomen.com/user/token'
,
{
method
:
'POST'
,
method
:
'POST'
,
headers
:
{
Authorization
:
'Bearer '
+
JSON
.
parse
(
localStorage
.
getItem
(
'user'
)
||
''
)?.
token
},
});
});
}
}
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