mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 02:54:11 +08:00
feat: OnDiscardedError typings and event (#6777)
* feat: OnDiscardedError typings and event * remove ios and android from DiscardedErrorEventData
This commit is contained in:
@ -81,6 +81,13 @@ application.on(application.uncaughtErrorEvent, function(args: application.Unhand
|
||||
console.log("### stack: " + args.error.stack);
|
||||
});
|
||||
|
||||
application.on(application.discardedErrorEvent, function(args: application.DiscardedErrorEventData) {
|
||||
console.log("### [Discarded] NativeScriptError: " + args.error);
|
||||
console.log("### [Discarded] nativeException: " + (<any>args.error).nativeException);
|
||||
console.log("### [Discarded] stackTrace: " + (<any>args.error).stackTrace);
|
||||
console.log("### [Discarded] stack: " + args.error.stack);
|
||||
});
|
||||
|
||||
application.setCssFileName("ui-tests-app/app.css");
|
||||
|
||||
application.start({ moduleName: "ui-tests-app/main-page" });
|
||||
|
@ -90,6 +90,12 @@ application.on(application.uncaughtErrorEvent, function (args: application.Unhan
|
||||
console.log((<any>args.error).stackTrace || (<any>args.error).stack);
|
||||
});
|
||||
|
||||
application.on(application.discardedErrorEvent, function (args: application.DiscardedErrorEventData) {
|
||||
console.log("[Discarded] NativeScriptError: " + args.error);
|
||||
console.log((<any>args.error).nativeException || (<any>args.error).nativeError);
|
||||
console.log((<any>args.error).stackTrace || (<any>args.error).stack);
|
||||
});
|
||||
|
||||
// Android activity events
|
||||
if (application.android) {
|
||||
application.android.on(application.AndroidApplication.activityCreatedEvent, function (args: application.AndroidActivityBundleEventData) {
|
||||
|
@ -38,10 +38,11 @@ import {
|
||||
getRootView,
|
||||
iOSApplication,
|
||||
LoadAppCSSEventData,
|
||||
UnhandledErrorEventData
|
||||
UnhandledErrorEventData,
|
||||
DiscardedErrorEventData
|
||||
} from "./application";
|
||||
|
||||
export { UnhandledErrorEventData, CssChangedEventData, LoadAppCSSEventData };
|
||||
export { UnhandledErrorEventData, DiscardedErrorEventData, CssChangedEventData, LoadAppCSSEventData };
|
||||
|
||||
export const launchEvent = "launch";
|
||||
export const suspendEvent = "suspend";
|
||||
@ -50,6 +51,7 @@ export const resumeEvent = "resume";
|
||||
export const exitEvent = "exit";
|
||||
export const lowMemoryEvent = "lowMemory";
|
||||
export const uncaughtErrorEvent = "uncaughtError";
|
||||
export const discardedErrorEvent = "discardedError";
|
||||
export const orientationChangedEvent = "orientationChanged";
|
||||
|
||||
let cssFile: string = "./app.css";
|
||||
@ -122,3 +124,7 @@ export function addCss(cssText: string): void {
|
||||
global.__onUncaughtError = function (error: NativeScriptError) {
|
||||
events.notify(<UnhandledErrorEventData>{ eventName: uncaughtErrorEvent, object: app, android: error, ios: error, error: error });
|
||||
}
|
||||
|
||||
global.__onDiscardedError = function (error: NativeScriptError) {
|
||||
events.notify(<DiscardedErrorEventData>{ eventName: discardedErrorEvent, object: app, error: error });
|
||||
}
|
||||
|
17
tns-core-modules/application/application.d.ts
vendored
17
tns-core-modules/application/application.d.ts
vendored
@ -21,6 +21,11 @@ export var displayedEvent: string;
|
||||
*/
|
||||
export var uncaughtErrorEvent: string;
|
||||
|
||||
/**
|
||||
* String value used when hooking to discardedError event.
|
||||
*/
|
||||
export var discardedErrorEvent: string;
|
||||
|
||||
/**
|
||||
* String value used when hooking to suspend event.
|
||||
*/
|
||||
@ -103,6 +108,13 @@ export interface UnhandledErrorEventData extends ApplicationEventData {
|
||||
error: NativeScriptError;
|
||||
}
|
||||
|
||||
/**
|
||||
* Event data containing information about discarded application errors.
|
||||
*/
|
||||
export interface DiscardedErrorEventData extends ApplicationEventData {
|
||||
error: NativeScriptError;
|
||||
}
|
||||
|
||||
/**
|
||||
* Event data containing information about application css change.
|
||||
*/
|
||||
@ -262,6 +274,11 @@ export function on(event: "lowMemory", callback: (args: ApplicationEventData) =>
|
||||
*/
|
||||
export function on(event: "uncaughtError", callback: (args: UnhandledErrorEventData) => void, thisArg?: any);
|
||||
|
||||
/**
|
||||
* This event is raised when an discarded error occurs while the application is running.
|
||||
*/
|
||||
export function on(event: "discardedError", callback: (args: DiscardedErrorEventData) => void, thisArg?: any);
|
||||
|
||||
/**
|
||||
* This event is raised the orientation of the current device has changed.
|
||||
*/
|
||||
|
1
tns-core-modules/module.d.ts
vendored
1
tns-core-modules/module.d.ts
vendored
@ -54,6 +54,7 @@ declare namespace NodeJS {
|
||||
__onLiveSync: (context?: { type: string, module: string }) => void;
|
||||
__onLiveSyncCore: () => void;
|
||||
__onUncaughtError: (error: NativeScriptError) => void;
|
||||
__onDiscardedError: (error: NativeScriptError) => void;
|
||||
TNS_WEBPACK?: boolean;
|
||||
__requireOverride?: (name: string, dir: string) => any;
|
||||
}
|
||||
|
Reference in New Issue
Block a user