diff --git a/extensions/amp-list/0.1/amp-list.js b/extensions/amp-list/0.1/amp-list.js index c3106129709b..44eb0d6e441c 100644 --- a/extensions/amp-list/0.1/amp-list.js +++ b/extensions/amp-list/0.1/amp-list.js @@ -852,7 +852,7 @@ export class AmpList extends AMP.BaseElement { userAssert( response, 'Failed fetching JSON data: XHR Failed fetching ' + - `(${request.xhrUrl}): received no response.` + `(${this.buildElidedUrl_(request)}): received no response.` ); const init = response['init']; if (init) { @@ -860,7 +860,8 @@ export class AmpList extends AMP.BaseElement { if (status >= 300) { /** HTTP status codes of 300+ mean redirects and errors. */ throw user().createError( - `Failed fetching JSON data (${request.xhrUrl}): HTTP error`, + `Failed fetching JSON data (${this.buildElidedUrl_(request)})` + + ': HTTP error', status ); } @@ -868,8 +869,8 @@ export class AmpList extends AMP.BaseElement { userAssert( typeof response['html'] === 'string', 'Failed fetching JSON data: XHR Failed fetching ' + - `(${request.xhrUrl}): Expected response with format ` + - 'html: }. Received: ', + `(${this.buildElidedUrl_(request)}): Expected response with ` + + 'format {html: }. Received: ', response ); request.fetchOpt.responseType = 'application/json'; @@ -878,7 +879,7 @@ export class AmpList extends AMP.BaseElement { (error) => { throw user().createError( 'Failed fetching JSON data: XHR Failed fetching ' + - `(${request.xhrUrl})`, + `(${this.buildElidedUrl_(request)})`, error ); } @@ -892,6 +893,17 @@ export class AmpList extends AMP.BaseElement { }); } + /** + * Builds an elided, shortened URL suitable for display in error messages from + * the given request. + * @param {!FetchRequestDef} request + * @return {string} + */ + buildElidedUrl_(request) { + const url = Services.urlForDoc(this.element).parse(request.xhrUrl); + return `${url.origin}/...`; + } + /** * Schedules a fetch result to be rendered in the near future. * @param {!Array|!JsonObject|undefined} data diff --git a/extensions/amp-list/0.1/test/test-amp-list.js b/extensions/amp-list/0.1/test/test-amp-list.js index bae07f27a713..5cfb997fa78d 100644 --- a/extensions/amp-list/0.1/test/test-amp-list.js +++ b/extensions/amp-list/0.1/test/test-amp-list.js @@ -829,7 +829,7 @@ describes.repeated( return expect( list.layoutCallback() ).to.eventually.be.rejectedWith( - /XHR Failed fetching \(https:\/\/data.com.+?\): error/ + /XHR Failed fetching \(https:\/\/data.com\/\.\.\.\): error/ ); }); @@ -853,7 +853,7 @@ describes.repeated( return expect( list.layoutCallback() ).to.eventually.be.rejectedWith( - /fetching JSON data \(https:\/\/data.com.+?\): HTTP error 400/ + /fetching JSON data \(https:\/\/data.com\/\.\.\.\): HTTP error 400/ ); });