virtuacoplenny 1b91e0bc2f improve invite error handling (#2649)
* fix(invite): do not send empty queries for people search

The endpoint might return an error if an empty query is sent.

* fix(invite): add error logging for failed people directory requests

The error currently being passed through from $.getJSON ended up
being an empty string plus was not getting logged. So switch to
fetch to move along with jquery killing and log the error.

* fix(dial-in): add error logging for failed requests

* ref(invite): create a fetch helper to remove duplicate logic
2018-03-23 09:37:04 -07:00

29 lines
778 B
JavaScript

const logger = require('jitsi-meet-logger').getLogger(__filename);
/**
* Wrapper around fetch GET requests to handle json-ifying the response
* and logging errors.
*
* @param {string} url - The URL to perform a GET against.
* @returns {Promise<Object>} The response body, in JSON format, will be
* through the Promise.
*/
export function doGetJSON(url) {
return fetch(url)
.then(response => {
const jsonify = response.json();
if (response.ok) {
return jsonify;
}
return jsonify
.then(result => Promise.reject(result));
})
.catch(error => {
logger.error('Error performing get:', url, error);
return Promise.reject(error);
});
}