11import { Exceptionless } from "../../node_modules/@exceptionless/browser/dist/index.min.js" ;
2+ import { divide } from "./math.js" ;
23
34Exceptionless . startup ( c => {
45 c . apiKey = "LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw" ;
@@ -24,81 +25,94 @@ Exceptionless.startup(c => {
2425 } ;
2526
2627 c . defaultTags . push ( "Example" , "JavaScript" ) ;
28+ c . settings [ "@@error:MediaError" ] = "Off"
2729} ) ;
2830
29- function getNonexistentData ( ) {
30- /* random comment */ nonexistentArray [ arguments [ 0 ] ] ; // second random comment;
31- }
32-
33- function sendEvents ( numberToSends , eventType ) {
34- for ( var index = 0 ; index < numberToSends ; index ++ ) {
35- switch ( eventType || getRandomInt ( 0 , 5 ) ) {
36- case 0 : {
37- throwIndexOutOfRange ( ) ;
38- break ;
39- }
40- case 1 : {
41- exceptionless . ExceptionlessClient . default . submitLog ( "sendEvents" , "This is a test trace message" , "trace" ) ;
42- break ;
43- }
44- case 2 : {
45- exceptionless . ExceptionlessClient . default . submitLog ( "sendEvents" , "This is a test debug message" , "debug" ) ;
46- break ;
47- }
48- case 3 : {
49- exceptionless . ExceptionlessClient . default . submitLog ( "sendEvents" , "This is a test info message" , "info" ) ;
50- break ;
51- }
52- case 4 : {
53- exceptionless . ExceptionlessClient . default . submitLog ( "sendEvents" , "This is a test warn message" , "warn" ) ;
54- break ;
55- }
56- case 5 : {
57- exceptionless . ExceptionlessClient . default . submitLog ( "sendEvents" , "This is a test error message" , "error" ) ;
58- break ;
59- }
60- }
31+ document . addEventListener ( "DOMContentLoaded" , ( ) => {
32+ const elements = document . querySelectorAll ( ".submit-log" ) ;
33+ for ( const element of elements ) {
34+ element . addEventListener ( "click" , ( event ) => {
35+ const level = event . target . attributes [ "data-level" ] ;
36+ Exceptionless . submitLog ( "sendEvents" , `This is a log message with level: ${ level || "<no log level>" } ` , level ) ;
37+ } ) ;
6138 }
62- }
6339
64- function getRandomInt ( min , max ) {
65- exceptionless . ExceptionlessClient . default . submitLog ( "getting random int min:" + min + " max:" + max ) ;
66- return Math . floor ( Math . random ( ) * ( max - min + 1 ) ) + min ;
67- }
40+ document . querySelector ( "#throw-custom-error" ) . addEventListener ( "click" , ( ) => {
41+ throw new CustomError ( "A Custom Error" , 500 ) ;
42+ } ) ;
6843
69- function throwDivisionByZero ( ) {
70- return divide ( 10 , 0 ) ;
71- }
44+ document . querySelector ( "#throw-division-by-zero-error" ) . addEventListener ( "click" , ( ) => {
45+ divide ( 10 , 0 ) ;
46+ } ) ;
7247
73- function throwStringError ( ) {
74- return throwStringErrorImpl ( "string error message" ) ;
75- }
48+ document . querySelector ( "#throw-index-out-of-range" ) . addEventListener ( "click" , ( ) => {
49+ throwIndexOutOfRange ( ) ;
50+ } ) ;
51+
52+ document . querySelector ( "#throw-index-out-of-range-custom-stacking" ) . addEventListener ( "click" , ( ) => {
53+ throwIndexOutOfRange ( 1 , true ) ;
54+ } ) ;
55+
56+ document . querySelector ( "#throw-string-error" ) . addEventListener ( "click" , ( ) => {
57+ throwStringError ( ) ;
58+ } ) ;
59+
60+ document . querySelector ( "#throw-ignored-error" ) . addEventListener ( "click" , ( ) => {
61+ throw new MediaError ( "An Ignored Exception Type" ) ;
62+ } ) ;
63+
64+ document . querySelector ( "#config-settings-log" ) . addEventListener ( "click" , ( ) => {
65+ console . log ( Exceptionless . config . settings ) ;
66+ } ) ;
67+ } ) ;
7668
7769function throwIndexOutOfRange ( indexer , withCustomStacking ) {
7870 try {
7971 getNonexistentData ( indexer ) ;
8072 } catch ( e ) {
81- var client = exceptionless . ExceptionlessClient . default ;
8273 if ( withCustomStacking ) {
8374 if ( Math . random ( ) < .5 ) {
84- client . createException ( e ) . setManualStackingKey ( "MyCustomStackingKey" ) . submit ( ) ;
75+ Exceptionless . createException ( e ) . setManualStackingKey ( "MyCustomStackingKey" ) . submit ( ) ;
8576 } else {
86- client . createException ( e ) . setManualStackingInfo ( {
77+ Exceptionless . createException ( e ) . setManualStackingInfo ( {
8778 File : "index.js" ,
8879 Function : "throwIndexOutOfRange"
8980 } , "Custom Index Out Of Range Exception" ) . submit ( ) ;
9081 }
9182 } else {
92- client . submitException ( e ) ;
83+ Exceptionless . submitException ( e ) ;
9384 }
9485 }
9586}
9687
88+ function getNonexistentData ( ...args ) {
89+ /* random comment */ nonexistentArray [ args [ 0 ] ] ; // second random comment;
90+ }
91+
92+ function throwStringError ( ) {
93+ return throwStringErrorImpl ( "string error message" ) ;
94+ }
95+
9796function throwStringErrorImpl ( message ) {
98- throw new Error ( message ) ;
97+ throw message ;
9998}
10099
101- function logClientConfigurationSettings ( ) {
102- var client = exceptionless . ExceptionlessClient . default ;
103- console . log ( client . config . settings ) ;
100+ class CustomError extends Error {
101+ constructor ( message , code ) {
102+ super ( message ) ;
103+ this . name = "CustomError" ;
104+ this . code = code ; // Extra property;
105+ }
106+
107+ getValue ( ) {
108+ return 5 ;
109+ }
110+
111+ getPromiseValue ( ) {
112+ return new Promise ( r => r ( { expensive : "call" } ) ) ;
113+ }
114+
115+ get getThrowsError ( ) {
116+ throw new Error ( "Not Implemented" ) ;
117+ }
104118}
0 commit comments