Skip to content

Commit deb0b6a

Browse files
committed
Display a nice error message if someone uses the toolbar button and there is no data
1 parent 633fdf7 commit deb0b6a

File tree

1 file changed

+16
-26
lines changed

1 file changed

+16
-26
lines changed

resources/scripts/ext.dota2WebApi.toolbar.js

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -145,18 +145,13 @@ $( () => {
145145
$status.text( 'In progress...' )
146146
.addClass( 'loading' );
147147

148-
$.ajax( {
149-
url: mw.util.wikiScript( 'api' ),
150-
dataType: 'json',
151-
type: 'POST',
152-
data: {
153-
action: 'dota2dbapi',
154-
matchid: vars.matchIDs[ i ],
155-
pagename: mw.config.get( 'wgPageName' ),
156-
format: 'json'
157-
}
148+
const api = new mw.Api();
149+
api.post( {
150+
action: 'dota2dbapi',
151+
matchid: vars.matchIDs[ i ],
152+
pagename: mw.config.get( 'wgPageName' )
158153
} )
159-
.done( ( data ) => {
154+
.then( ( data ) => {
160155
if ( data.error !== undefined || data.dota2dbapi.error !== undefined ) {
161156
$status.text( data.error.info || data.dota2dbapi.error );
162157
$status.removeClass( 'loading' );
@@ -245,8 +240,8 @@ $( () => {
245240
$status.text( 'Success' );
246241
$status.removeClass( 'loading' );
247242
} )
248-
.fail( ( error ) => {
249-
$status.text( error.responseJSON.dota2dbapi.error );
243+
.catch( ( type, error ) => {
244+
$status.text( error.xhr.responseJSON.dota2dbapi.error );
250245
} )
251246
.always( () => {
252247
++i;
@@ -480,18 +475,13 @@ $( () => {
480475
$status.text( 'In progress...' )
481476
.addClass( 'loading' );
482477

483-
$.ajax( {
484-
url: mw.util.wikiScript( 'api' ),
485-
dataType: 'json',
486-
type: 'POST',
487-
data: {
488-
action: 'dota2dbapi',
489-
matchid: vars.matchIDs[ i ],
490-
pagename: mw.config.get( 'wgPageName' ),
491-
format: 'json'
492-
}
478+
const api = new mw.Api();
479+
api.post( {
480+
action: 'dota2dbapi',
481+
matchid: vars.matchIDs[ i ],
482+
pagename: mw.config.get( 'wgPageName' )
493483
} )
494-
.done( ( data ) => {
484+
.then( ( data ) => {
495485
if ( data.error !== undefined || data.dota2dbapi.error !== undefined ) {
496486
$status.text( data.error.info || data.dota2dbapi.error );
497487
$status.removeClass( 'loading' );
@@ -577,8 +567,8 @@ $( () => {
577567

578568
$status.removeClass( 'loading' );
579569
} )
580-
.fail( ( error ) => {
581-
$status.text( error.responseJSON.dota2dbapi.error );
570+
.catch( ( type, error ) => {
571+
$status.text( error.xhr.responseJSON.dota2dbapi.error );
582572
} )
583573
.always( () => {
584574
++i;

0 commit comments

Comments
 (0)