无法解析 POST 对 redux observable 的调用
Unable to resolve POST call on redux observable
我正在开发一个 React 本机应用程序,并正在使用 Observable.fromPromise 进行 POST 调用,我收到以下响应,但我不确定如何捕获响应代码,我也收到了一些警告
回复:
PromiseObservable {_isScalar: false, promise: Promise, scheduler: undefined}
promise: Promise
_40: 0
_55: Promise
_40: 0
_55: Promise
_40: 0
_51: 3
_55: Response
bodyUsed: true
headers: Headers {map: {…}}
ok: true
status: 200
statusText: undefined
type: "default"
url: "http://localhost:9999/testPath/pathData"
_bodyBlob: Blob {_data: {…}}
_bodyInit: Blob {_data: {…}}
__proto__: Object
_65: 2
_72: null
__proto__: Object
_65: 3
_72: null
__proto__: Object
_65: 3
_72: null
__proto__: Object
scheduler: undefined
_isScalar: false
__proto__: Observable
警告:
YellowBox.js:67 Possible Unhandled Promise Rejection (id: 0):
Response {
"_bodyBlob": Blob {
"_data": Object {
"blobId": "D985543E-CD51-470C-91F9-3407AE59FDA1",
"name": "test-data",
"offset": 0,
"size": 0,
"type": "application/json",
},
},
"_bodyInit": Blob {
"_data": Object {
"blobId": "D985543E-CD51-470C-91F9-3407AE59FDA1",
"name": "test-data",
"offset": 0,
"size": 0,
"type": "application/json",
},
},
"bodyUsed": true,
"headers": Headers {
"map": Object {
"content-type": "application/json; charset=UTF-8",
"server": "Jetty(9.2.z-SNAPSHOT)",
"transfer-encoding": "Identity",
},
},
"ok": true,
"status": 200,
"statusText": undefined,
"type": "default",
"url": "http://localhost:9999/testPath/pathData",
}
我正在使用 mergeMap 来捕获响应,不确定为什么在这种情况下它不起作用
代码:
const testEpic: Epic<Action, ReduxState> = (
action$: ActionsObservable<any>,
store: MiddlewareAPI<any, ReduxState>,
) =>
action$
.ofType(TEST_GET)
.mergeMap((action) => {
return Observable.merge(
.fetch('/testPath/pathData', payload) // return part which is working properly
.mergeMap((response) => {
// calls not coming here for POST, PUT, DELETE even though it is status 200
})
)
}
)
.catch((error) => {
})
试试这个
fetch("/testPath/pathData", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
我已经解决了,实际上它进入了内部 'error' 因为 contentType
不匹配
我正在开发一个 React 本机应用程序,并正在使用 Observable.fromPromise 进行 POST 调用,我收到以下响应,但我不确定如何捕获响应代码,我也收到了一些警告
回复:
PromiseObservable {_isScalar: false, promise: Promise, scheduler: undefined}
promise: Promise
_40: 0
_55: Promise
_40: 0
_55: Promise
_40: 0
_51: 3
_55: Response
bodyUsed: true
headers: Headers {map: {…}}
ok: true
status: 200
statusText: undefined
type: "default"
url: "http://localhost:9999/testPath/pathData"
_bodyBlob: Blob {_data: {…}}
_bodyInit: Blob {_data: {…}}
__proto__: Object
_65: 2
_72: null
__proto__: Object
_65: 3
_72: null
__proto__: Object
_65: 3
_72: null
__proto__: Object
scheduler: undefined
_isScalar: false
__proto__: Observable
警告:
YellowBox.js:67 Possible Unhandled Promise Rejection (id: 0):
Response {
"_bodyBlob": Blob {
"_data": Object {
"blobId": "D985543E-CD51-470C-91F9-3407AE59FDA1",
"name": "test-data",
"offset": 0,
"size": 0,
"type": "application/json",
},
},
"_bodyInit": Blob {
"_data": Object {
"blobId": "D985543E-CD51-470C-91F9-3407AE59FDA1",
"name": "test-data",
"offset": 0,
"size": 0,
"type": "application/json",
},
},
"bodyUsed": true,
"headers": Headers {
"map": Object {
"content-type": "application/json; charset=UTF-8",
"server": "Jetty(9.2.z-SNAPSHOT)",
"transfer-encoding": "Identity",
},
},
"ok": true,
"status": 200,
"statusText": undefined,
"type": "default",
"url": "http://localhost:9999/testPath/pathData",
}
我正在使用 mergeMap 来捕获响应,不确定为什么在这种情况下它不起作用
代码:
const testEpic: Epic<Action, ReduxState> = (
action$: ActionsObservable<any>,
store: MiddlewareAPI<any, ReduxState>,
) =>
action$
.ofType(TEST_GET)
.mergeMap((action) => {
return Observable.merge(
.fetch('/testPath/pathData', payload) // return part which is working properly
.mergeMap((response) => {
// calls not coming here for POST, PUT, DELETE even though it is status 200
})
)
}
)
.catch((error) => {
})
试试这个
fetch("/testPath/pathData", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
我已经解决了,实际上它进入了内部 'error' 因为 contentType
不匹配