promisse typescript上的抛出错误失败
我正在尝试在我的API服务上创建一个netInfo检查器。这是我与端点连接的工作,我需要创建一个netInfo检查服务来处理连接错误:promisse typescript上的抛出错误失败,typescript,react-native,promise,try-catch,Typescript,React Native,Promise,Try Catch,我正在尝试在我的API服务上创建一个netInfo检查器。这是我与端点连接的工作,我需要创建一个netInfo检查服务来处理连接错误: loginExists(username) .then((status: string) => { setLoading(false); if (status == '200' || status) { const checkSAPData = checkUserSAPMock(usernam
loginExists(username)
.then((status: string) => {
setLoading(false);
if (status == '200' || status) {
const checkSAPData = checkUserSAPMock(username);
if (checkSAPData) {
navigation.navigate('LoginPassword', { document: username, sapData: checkSAPData });
} else {
navigation.navigate('LoginPassword', { document: username });
}
}
})
.catch(error => {
console.log('myerror: ' + JSON.stringify(error));
setLoading(false);
const checkSAPData = checkUserSAPMock(username);
if (checkSAPData) {
if (checkSAPData.Motorista.item.Autorizacao === "S")
navigation.navigate('SignUp', { data: checkSAPData });
else
navigation.navigate('LoginPassword', { document: username, sapData: checkSAPData });
} else
navigation.navigate('SignUp', { isNewUser: true, document: cpf });
});
在这里,我转到API服务来执行:
export function loginExists(username: string) {
const headers = new Headers({
'Content-Type': 'application/json',
});
// TODO: REMOVE
// debug
// if (username === '00000000000') {
// return API.get(`motoristas/cpf/09503054990/existe`);
// }
return API.get(`motoristas/cpf/${username}/existe`);
}
我的netInfo检查器,我在其中抛出错误:
get(endpoint: string, headersProp?: Headers | string[][] | Record<string, string>): Promise<any> {
return ConnectionChecker.getConnection().then(state => {
let headers = {
};
if (headersProp) {
headers = { ...headers, ...headersProp };
}
if (state.isConnected) {
return fetch(`${this.url}/${endpoint}`, {
method: 'GET',
headers
});
} else {
//Criar arquivo de constantes com erros da aplicacao/genericos.
const errorData = {
type: 'connection',
title: 'title',
message: 'message'
};
throw new Error(JSON.stringify(errorData));
}
}).then(this._handleError)
.then(this._handleContentType)
.catch(this._handleErrorCatch);
}
问题是:我的错误对象不正确。console.log()向我提供以下消息:
myerror: {"line":185244,"column":30,"sourceURL":"http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false"}
但这是我的错误:
{"type":"connection","title":"title","message":"message"}
有人能帮我吗?谢谢大家!!!o/如果你想重新抛出原来的错误,请不要做出新的错误,谢谢兄弟!!!回答一个问题,我会把它标记为正确的。o/
{"type":"connection","title":"title","message":"message"}