mirror of
https://github.com/ragestudio/linebridge.git
synced 2025-06-09 18:44:17 +00:00
handleResponse
This commit is contained in:
parent
2068821230
commit
a53d39b825
@ -76,6 +76,14 @@ class Bridge {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleResponse = async (response) => {
|
||||||
|
if (typeof this.params.onResponse === "function") {
|
||||||
|
return await this.params.onResponse(response)
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
updateEndpointMap = async () => {
|
updateEndpointMap = async () => {
|
||||||
this.map = await this.getMap()
|
this.map = await this.getMap()
|
||||||
|
|
||||||
@ -109,7 +117,7 @@ class Bridge {
|
|||||||
nameKey = "index"
|
nameKey = "index"
|
||||||
}
|
}
|
||||||
|
|
||||||
this.endpoints[fixedMethod][nameKey] = generateDispatcher(this.instance, fixedMethod, route, this.handleRequestContext)
|
this.endpoints[fixedMethod][nameKey] = generateDispatcher(this.instance, fixedMethod, route, this.handleRequestContext, this.handleResponse)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,7 +134,7 @@ class Bridge {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateDispatcher(instance, method, route, handleRequestContext) {
|
function generateDispatcher(instance, method, route, handleRequestContext, handleResponse) {
|
||||||
return function (body, query, options) {
|
return function (body, query, options) {
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
let requestParams = {
|
let requestParams = {
|
||||||
@ -148,14 +156,22 @@ function generateDispatcher(instance, method, route, handleRequestContext) {
|
|||||||
error: null,
|
error: null,
|
||||||
}
|
}
|
||||||
|
|
||||||
await instance(requestParams)
|
const request = await instance(requestParams)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
result.response = response
|
result.response = response
|
||||||
|
|
||||||
|
return response
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
result.error = error.response.data.error ?? error.response.data
|
result.error = error.response.data.error ?? error.response.data
|
||||||
|
|
||||||
|
return error
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (typeof handleResponse === "function") {
|
||||||
|
await handleResponse(request)
|
||||||
|
}
|
||||||
|
|
||||||
if (requestParams.parseData) {
|
if (requestParams.parseData) {
|
||||||
if (result.error) {
|
if (result.error) {
|
||||||
return reject(result.error)
|
return reject(result.error)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user