@@ -538,7 +538,10 @@ export default class GraphRedex<N extends GRND, E extends GRED> {
538538 return true ;
539539 }
540540 } else {
541- if ( data . every ( ( x ) => typeof x === "object" && "_id" in x ) ) {
541+ if (
542+ data . length > 0 &&
543+ data . every ( ( x ) => typeof x === "object" && "_id" in x )
544+ ) {
542545 if (
543546 confirm (
544547 "Returned data does not conain any edges. Make a highlight instead?" ,
@@ -547,7 +550,11 @@ export default class GraphRedex<N extends GRND, E extends GRED> {
547550 return this . highlightIfGraph ( data ) ;
548551 }
549552 } else {
550- throw "Rendering nodes is not implemented yet" ;
553+ if ( data . length == 0 ) {
554+ throw "result is empty " ;
555+ } else {
556+ throw "Rendering nodes is not implemented yet" ;
557+ }
551558 }
552559 }
553560 return false ;
@@ -781,10 +788,7 @@ export default class GraphRedex<N extends GRND, E extends GRED> {
781788 this . updateLangs ( ) ;
782789 form . classed ( "closed" , true ) ;
783790 } )
784- . catch ( ( e ) => {
785- console . log ( "ERROR" , e ) ;
786- alert ( "something went wrong\n\n" + e ) ;
787- } ) ;
791+ . catch ( errorAlert ) ;
788792
789793 return false ;
790794 } ) ;
@@ -812,17 +816,22 @@ export default class GraphRedex<N extends GRND, E extends GRED> {
812816 output . textContent = "success" ;
813817 form . classed ( "closed" , true ) ;
814818 } )
815- . catch ( ( e ) => {
819+ . catch ( ( data ) => {
820+ console . error ( [ data ] ) ;
816821 submitBtn . attr ( "disabled" , null ) ;
817- output . textContent = JSON . stringify ( e , null , 2 ) ;
818- if ( "e" in data ) {
819- output . textContent = data . e ;
820-
821- if ( "errors" in data ) {
822- const errEl = document . createElement ( "pre" ) ;
823- errEl . textContent = data . errors ;
824- output . appendChild ( errEl ) ;
822+ if ( typeof data == "object" ) {
823+ output . textContent = JSON . stringify ( data , null , 2 ) ;
824+ if ( "err" in data ) {
825+ output . textContent = data . err ;
826+
827+ if ( "errors" in data ) {
828+ const errEl = document . createElement ( "pre" ) ;
829+ errEl . textContent = data . errors ;
830+ output . appendChild ( errEl ) ;
831+ }
825832 }
833+ } else {
834+ output . textContent = data ;
826835 }
827836 } ) ;
828837 } ) ;
@@ -874,10 +883,14 @@ export default class GraphRedex<N extends GRND, E extends GRED> {
874883 }
875884 } )
876885 . catch ( ( error ) => {
877- if ( typeof error === "string" && error [ 0 ] === "< ") {
878- output . innerHTML = error ;
886+ if ( typeof error === "object " ) {
887+ output . textContent = error . err ?? JSON . stringify ( error ) ;
879888 } else {
880- output . textContent = "ERROR:" + error ;
889+ if ( typeof error === "string" && error [ 0 ] === "<" ) {
890+ output . innerHTML = error ;
891+ } else {
892+ output . textContent = "ERROR:" + error ;
893+ }
881894 }
882895 } ) ;
883896 } ) ;
@@ -990,7 +1003,7 @@ export default class GraphRedex<N extends GRND, E extends GRED> {
9901003 if ( name ) {
9911004 this . saveQry ( name , d3 . select ( "#qry" ) . property ( "value" ) )
9921005 . then ( ( ) => alert ( "saved" ) )
993- . catch ( ( x ) => alert ( x ) ) ;
1006+ . catch ( errorAlert ) ;
9941007 }
9951008 return false ;
9961009 } ) ;
@@ -1051,7 +1064,7 @@ export default class GraphRedex<N extends GRND, E extends GRED> {
10511064 . then ( ( ) => {
10521065 alert ( "removed" ) ;
10531066 } )
1054- . catch ( ( e ) => alert ( e ) ) ;
1067+ . catch ( errorAlert ) ;
10551068 }
10561069 return false ;
10571070 } ) ;
@@ -1063,7 +1076,7 @@ export default class GraphRedex<N extends GRND, E extends GRED> {
10631076 . then ( ( ) => {
10641077 alert ( "removed" ) ;
10651078 } )
1066- . catch ( ( e ) => alert ( e ) ) ;
1079+ . catch ( errorAlert ) ;
10671080 this . curExample = null ;
10681081 this . reset ( ) ;
10691082 }
@@ -1183,3 +1196,16 @@ function isInputDataArray<N extends GRND, E extends GRED>(
11831196 }
11841197 return false ;
11851198}
1199+
1200+ function errorAlert ( e : any ) {
1201+ console . error ( "ERROR" , e ) ;
1202+ if ( typeof e === "object" ) {
1203+ if ( e . err ?? false ) {
1204+ alert ( "something went wrong\n\n" + e . err ) ;
1205+ } else {
1206+ alert ( "something went wrong\n\n" + JSON . stringify ( e ) ) ;
1207+ }
1208+ } else {
1209+ alert ( "something went wrong\n\n" + e ) ;
1210+ }
1211+ }
0 commit comments