mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-23 23:24:39 +00:00
Better error handling for unexpected responses
Bug: T182639 Change-Id: Iea04fe41b4be8e15927e93f16cbb4bb44328374f
This commit is contained in:
parent
cd2b0baaf8
commit
ff49e7627b
BIN
resources/dist/index.js
vendored
BIN
resources/dist/index.js
vendored
Binary file not shown.
BIN
resources/dist/index.js.json
vendored
BIN
resources/dist/index.js.json
vendored
Binary file not shown.
|
@ -26,8 +26,6 @@ var RESTBASE_ENDPOINT = '/api/rest_v1/page/summary/',
|
|||
* @param {Function} ajax A function with the same signature as `jQuery.ajax`
|
||||
* @param {Object} config Configuration that affects the major behavior of the
|
||||
* gateway.
|
||||
* @param {Number} config.THUMBNAIL_SIZE The length of the major dimension of
|
||||
* the thumbnail.
|
||||
* @param {Function} extractParser A function that takes response and returns parsed extract
|
||||
* @return {RESTBaseGateway}
|
||||
*/
|
||||
|
@ -59,6 +57,14 @@ export default function createRESTBaseGateway( ajax, config, extractParser ) {
|
|||
fetch( title )
|
||||
.then(
|
||||
function ( page ) {
|
||||
// Endpoint response may be empty.
|
||||
if ( !page ) {
|
||||
page = { title: title };
|
||||
}
|
||||
// And extract may be omitted if empty string
|
||||
if ( page.extract === undefined ) {
|
||||
page.extract = '';
|
||||
}
|
||||
result.resolve(
|
||||
convertPageToModel( page, config.THUMBNAIL_SIZE, extractParser ) );
|
||||
},
|
||||
|
|
|
@ -272,6 +272,24 @@ QUnit.test( 'RESTBase gateway handles missing images ', function ( assert ) {
|
|||
);
|
||||
} );
|
||||
|
||||
QUnit.test( 'RESTBase gateway handles missing extracts', function ( assert ) {
|
||||
var api = this.sandbox.stub().returns( $.Deferred().resolve( {} ).promise() ),
|
||||
gateway = createRESTBaseGateway( api, DEFAULT_CONSTANTS, provideParsedExtract );
|
||||
|
||||
return gateway.getPageSummary( 'Test Title with missing extract' ).then( function ( result ) {
|
||||
assert.equal( result.extract, '!!', 'Extract' );
|
||||
} );
|
||||
} );
|
||||
|
||||
QUnit.test( 'RESTBase gateway handles no content success responses', function ( assert ) {
|
||||
var api = this.sandbox.stub().returns( $.Deferred().resolve( { status: 204 } ).promise() ),
|
||||
gateway = createRESTBaseGateway( api, DEFAULT_CONSTANTS, provideParsedExtract );
|
||||
|
||||
return gateway.getPageSummary( 'Test Title with empty response' ).then( function ( result ) {
|
||||
assert.equal( result.extract, '!!', 'Extract' );
|
||||
} );
|
||||
} );
|
||||
|
||||
QUnit.test( 'RESTBase gateway handles missing pages ', function ( assert ) {
|
||||
var response = {
|
||||
type: 'https://mediawiki.org/wiki/HyperSwitch/errors/not_found',
|
||||
|
|
Loading…
Reference in a new issue