Ich habe einen einfachen http-Aufruf mit einem Erfolgsrückruf. Wenn ich jedoch versuche, die ursprünglichen Parameter zurückzugeben, reagiere einen unbehandelten Verweigerungsverweigerungsfehler, wodurch mein Versand fehlschlägt :reactive-native, Abschlussvariable bewirkt, dass die Aktion fehlschlägt
export function deleteFriendRequest(userId) {
return dispatch => {
// dispatch(deleteFriendRequestSuccess({}, userId))
request.del({dispatch, path: `/friends/${userId}`, body: {}, deleteFriendRequestSuccess, deleteFriendRequestFailure, initialData: userId})
}
}
function deleteFriendRequestSuccess(payload, initialData) {
console.log('delete friend request success', payload, userId) // this works I get the correct user id
return {
type: FRIENDS_DELETE_FRIEND_REQUEST_SUCCESS,
payload: {sentId: initialData},
}
}
function deleteFriendRequestFailure(error) {
return {
type: FRIENDS_DELETE_FRIEND_REQUEST_FAILURE,
error,
}
}
export function del({dispatch, path, body, success, failure, initialData}) {
const url = API_URL + path
const token = store.getState().auth.token
fetch(url, {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
'AccessToken': token && token.token ? token.token : null,
'deviceUID': DeviceInfo.getUniqueID(),
},
body: JSON.stringify(body),
})
.then(function (response) {
if (response.status < 200 || response.status > 299) {
throw ({errorMessage: 'Invalid response'}, response)
} else {
return response
}
})
.then(response => response.json())
.then(checkForResponseError)
.then(json => {
dispatch(success(json, initialData))
})
.catch(err => {
dispatch(failure(err))
})
}
Ursachen:
Possible Unhandled Promise Rejection (id: 0):
failure is not a function
TypeError: failure is not a function
at http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false&hot=true:84194:10
at tryCallOne (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false&hot=true:29539:8)
at http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false&hot=true:29625:9
at JSTimersExecution.callbacks.(anonymous function) (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false&hot=true:12854:13)
at Object.callTimer (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false&hot=true:12686:1)
at Object.callImmediatesPass (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false&hot=true:12744:19)
at Object.callImmediates (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false&hot=true:12759:25)
at http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false&hot=true:11613:43
at guard (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false&hot=true:11518:1)
at MessageQueue.__callImmediates (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false&hot=true:11613:1)
Jede Idee, wie diese zu lösen?
ah, sorry, ich habe die deleteFriendRequestFailure Funktion im Snippet oben nicht hinzufügen, es war spät und ich war müde, es ist definiert, noch der gleiche Fehler ist geworfen, bearbeite ich die Antwort, um es einzuschließen – ospfranco
Hat die aktualisierte Antwort Ihnen geholfen, Ihr Problem zu lösen? Wenn ja, bitte als Lösung markieren. Wenn nicht, lassen Sie mich wissen, was los ist, damit ich es beheben kann. – DDS
Vielen Dank für Ihre Anmerkungen, ich habe den Code nicht korrekt aktualisiert, während ich schließlich mit genau dem gleichen Code wie Sie endete (aber ich habe mir Ihre aktualisierte Antwort bis jetzt nicht angesehen), ich verstehe nicht, warum ich einen übergeben habe Objekt bewirkt, dass die Parameter in der Sperrung verfügbar bleiben, jede Klärung wäre sehr willkommen. – ospfranco