feat: OnDiscardedError typings and event (#6777)

* feat: OnDiscardedError typings and event

* remove ios and android from DiscardedErrorEventData
This commit is contained in:
Vasil Trifonov
2019-01-09 18:24:25 +02:00
committed by GitHub
parent 4cda0e7345
commit 28db2afbd4
5 changed files with 47 additions and 10 deletions

View File

@ -81,6 +81,13 @@ application.on(application.uncaughtErrorEvent, function(args: application.Unhand
console.log("### stack: " + args.error.stack); 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.setCssFileName("ui-tests-app/app.css");
application.start({ moduleName: "ui-tests-app/main-page" }); application.start({ moduleName: "ui-tests-app/main-page" });

View File

@ -90,6 +90,12 @@ application.on(application.uncaughtErrorEvent, function (args: application.Unhan
console.log((<any>args.error).stackTrace || (<any>args.error).stack); 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 // Android activity events
if (application.android) { if (application.android) {
application.android.on(application.AndroidApplication.activityCreatedEvent, function (args: application.AndroidActivityBundleEventData) { application.android.on(application.AndroidApplication.activityCreatedEvent, function (args: application.AndroidActivityBundleEventData) {

View File

@ -38,10 +38,11 @@ import {
getRootView, getRootView,
iOSApplication, iOSApplication,
LoadAppCSSEventData, LoadAppCSSEventData,
UnhandledErrorEventData UnhandledErrorEventData,
DiscardedErrorEventData
} from "./application"; } from "./application";
export { UnhandledErrorEventData, CssChangedEventData, LoadAppCSSEventData }; export { UnhandledErrorEventData, DiscardedErrorEventData, CssChangedEventData, LoadAppCSSEventData };
export const launchEvent = "launch"; export const launchEvent = "launch";
export const suspendEvent = "suspend"; export const suspendEvent = "suspend";
@ -50,6 +51,7 @@ export const resumeEvent = "resume";
export const exitEvent = "exit"; export const exitEvent = "exit";
export const lowMemoryEvent = "lowMemory"; export const lowMemoryEvent = "lowMemory";
export const uncaughtErrorEvent = "uncaughtError"; export const uncaughtErrorEvent = "uncaughtError";
export const discardedErrorEvent = "discardedError";
export const orientationChangedEvent = "orientationChanged"; export const orientationChangedEvent = "orientationChanged";
let cssFile: string = "./app.css"; let cssFile: string = "./app.css";
@ -122,3 +124,7 @@ export function addCss(cssText: string): void {
global.__onUncaughtError = function (error: NativeScriptError) { global.__onUncaughtError = function (error: NativeScriptError) {
events.notify(<UnhandledErrorEventData>{ eventName: uncaughtErrorEvent, object: app, android: error, ios: error, error: error }); 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 });
}

View File

@ -21,6 +21,11 @@ export var displayedEvent: string;
*/ */
export var uncaughtErrorEvent: 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. * String value used when hooking to suspend event.
*/ */
@ -103,6 +108,13 @@ export interface UnhandledErrorEventData extends ApplicationEventData {
error: NativeScriptError; 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. * 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); 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. * This event is raised the orientation of the current device has changed.
*/ */

View File

@ -54,6 +54,7 @@ declare namespace NodeJS {
__onLiveSync: (context?: { type: string, module: string }) => void; __onLiveSync: (context?: { type: string, module: string }) => void;
__onLiveSyncCore: () => void; __onLiveSyncCore: () => void;
__onUncaughtError: (error: NativeScriptError) => void; __onUncaughtError: (error: NativeScriptError) => void;
__onDiscardedError: (error: NativeScriptError) => void;
TNS_WEBPACK?: boolean; TNS_WEBPACK?: boolean;
__requireOverride?: (name: string, dir: string) => any; __requireOverride?: (name: string, dir: string) => any;
} }