@@ -3051,10 +3051,36 @@ if (!LABKEY.DataRegions) {
30513051
30523052 var _chainSelectionCountCallback = function ( region , config ) {
30533053
3054- var success = LABKEY . Utils . getOnSuccess ( config ) ;
3054+ const failure = LABKEY . Utils . getOnFailure ( config ) ;
3055+ config . failure = function ( error ) {
3056+ region . selectionLoading = false ;
3057+
3058+ let msg = 'Error setting selection' ;
3059+ if ( error && error . exception ) msg += ': ' + error . exception ;
3060+ config . scope . addMessage ( msg , 'selection' ) ;
3061+
3062+ if ( $ . isFunction ( failure ) ) {
3063+ failure . call ( config . scope , error ) ;
3064+ }
3065+ }
30553066
30563067 // On success, update the current selectedCount on this DataRegion and fire the 'selectchange' event
3057- config . success = function ( data ) {
3068+ const success = LABKEY . Utils . getOnSuccess ( config ) ;
3069+ config . success = function ( data , response ) {
3070+
3071+ // Workaround for GitHub Issue 778 where the response payload is JSON but the response has been
3072+ // configured by the server as non-JSON.
3073+ if ( ! data && response ?. responseText ) {
3074+ try {
3075+ data = JSON . parse ( response . responseText ) ;
3076+ } catch ( e ) {
3077+ const msg = 'failed to parse response' ;
3078+ console . error ( msg , e , response ) ;
3079+ config . failure . call ( config . scope , { exception : msg } ) ;
3080+ return ;
3081+ }
3082+ }
3083+
30583084 region . removeMessage ( 'selection' ) ;
30593085 region . selectionModified = true ;
30603086 region . selectionLoading = false ;
@@ -3067,19 +3093,6 @@ if (!LABKEY.DataRegions) {
30673093 }
30683094 } ;
30693095
3070- var failure = LABKEY . Utils . getOnFailure ( config ) ;
3071- config . failure = function ( error ) {
3072- region . selectionLoading = false ;
3073-
3074- let msg = 'Error setting selection' ;
3075- if ( error && error . exception ) msg += ': ' + error . exception ;
3076- config . scope . addMessage ( msg , 'selection' ) ;
3077-
3078- if ( $ . isFunction ( failure ) ) {
3079- failure . call ( config . scope , error ) ;
3080- }
3081- }
3082-
30833096 return config ;
30843097 } ;
30853098
@@ -4505,15 +4518,12 @@ if (!LABKEY.DataRegions) {
45054518 }
45064519
45074520 // NOTE: ignore maxRows, showRows, and offset
4508- } else {
4509- params = LABKEY . ActionURL . getParameters ( config . url ) ;
4510- config . url = LABKEY . ActionURL . buildURL ( 'query' , 'selectAll.api' , config . containerPath ) ;
45114521 }
45124522
45134523 LABKEY . Ajax . request ( {
45144524 url : config . url ,
45154525 method : 'POST' ,
4516- jsonData : params ,
4526+ params : params ,
45174527 success : LABKEY . Utils . getCallbackWrapper ( LABKEY . Utils . getOnSuccess ( config ) , region ) ,
45184528 failure : LABKEY . Utils . getCallbackWrapper ( LABKEY . Utils . getOnFailure ( config ) , region , true )
45194529 } ) ;
0 commit comments