Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android not sending fetch in setNativeExceptionHandler #155

Open
smallzZz8 opened this issue Oct 20, 2021 · 6 comments
Open

Android not sending fetch in setNativeExceptionHandler #155

smallzZz8 opened this issue Oct 20, 2021 · 6 comments

Comments

@smallzZz8
Copy link

I am trying to send an error to a webhook on native crashes. Everything works fine on iOS but does not work on android. Does anyone have a solution?

I have confirmed that the setNativeExceptionHandler is running for android since it does print the console log. Any Idea?

setNativeExceptionHandler((errorString) => {
	// You can do something like call an api to report to dev team here
	console.log('setNativeExceptionHandler');
	try {
		const myHeaders = new Headers();
		myHeaders.append('Content-Type', 'application/json');

		const raw = `{"text": "Type: 'setNativeExceptionHandler',\nPlatform: ${
			Platform.OS
		},\nIs Fatal: Yes,\nCan OTA?: No\nError Message: ${errorString.toString().split('"').join("'")}\n-----\n\n"}`;

		const requestOptions = {
			method: 'POST',
			headers: myHeaders,
			body: raw
		};

		fetch('THEURL', requestOptions)
			.then((response) => response.text())
			.then((result) => console.log(result))
			.catch((error) => console.log('error', error));
	} catch (error) {
		console.log(error);
	}
});```
@bombillazo
Copy link

I have the same issue, Im trying to send Crashlytics info in the native error handler on the Android app but nothing inside this function runs.

@W1nstar
Copy link

W1nstar commented Aug 3, 2022

Still happening on 2022. Method gets executed in a js thread, logs are shown in logcat but a simple does not work. It doesn't even throw an error to catch, so I'm out of ideas. Of cource, Sentry isn't working either.

@bombillazo did you find any workaround?

@bombillazo
Copy link

bombillazo commented Aug 4, 2022

@W1nstar I think it did, I implemented it like this:

const nativeExceptionhandler: NativeExceptionHandler = (error) => {
  console.debug('NATIVE EXCEPTION!');
  crashlytics().recordError(new Error(error));
};

setNativeExceptionHandler(nativeExceptionhandler, false, false);

@W1nstar
Copy link

W1nstar commented Aug 5, 2022

@bombillazo
thanks a ton for the input!

I'm unfamiliar with crashlytics, but I guess it writes a file with the exception, for a later use? By my own findings, it seems like theres no way to make an http request of any kind inside nativeExceptionHandler.

@bombillazo
Copy link

Verify your Android HTTP setup, I believe by default some modern android versions block http by default, I'm not an expert in Crashlytics either but so far we do get events streamed to firebase.

@W1nstar
Copy link

W1nstar commented Aug 8, 2022

Yeah, I did, everything works correctly. Tested it on Androids 5 to 9, emulators and phyiscal terminals, same issue. Guess I'll have to store the event and somehow send it later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants