Skip to content
Snippets Groups Projects
Select Git revision
  • 04a640c8addc58b3e43a5067cd9a6f8ec726c3b9
  • master default protected
2 results

01-multiple-inheritance.cpp

Blame
  • error.js 3.82 KiB
    import {send as notify} from './notification';
    import {i18n} from "./i18n";
    
    /**
     * Escapes html
     *
     * @param string
     * @returns {string}
     */
    export const escapeHTML = (string) => {
        const pre = document.createElement('pre');
        const text = document.createTextNode(string);
        pre.appendChild(text);
    
        return pre.innerHTML;
    };
    
    /**
     * Strips html
     *
     * @param string
     * @returns {string}
     */
    export const stripHTML = (string) => {
        var div = document.createElement("div");
        div.innerHTML = string;
    
        return div.textContent || div.innerText || "";
    };
    
    /**
     * We need this mixin so we can use this.sendSetPropertyEvent to post analytics events
     */
    export const errorMixin = {
        /**
         * Error handling for XHR errors
         *
         * @param jqXHR
         * @param textStatus
         * @param errorThrown
         * @param icon
         */
        handleXhrError(jqXHR, textStatus, errorThrown, icon = "sad") {
            // return if user aborted the request
            if (textStatus === "abort") {
                return;
            }
    
            let body;
    
            if (jqXHR.responseJSON !== undefined && jqXHR.responseJSON["hydra:description"] !== undefined) {
                // response is a JSON-LD
                body = jqXHR.responseJSON["hydra:description"];
            } else if (jqXHR.responseJSON !== undefined && jqXHR.responseJSON['detail'] !== undefined) {
                // response is a plain JSON
                body = jqXHR.responseJSON['detail'];
            } else {
                // no description available
                body = textStatus;
    
                if (errorThrown) {
                    body += ' - ' + errorThrown;
                }
            }
    
            // if the server is not reachable at all
            if (jqXHR.status === 0) {
                body = i18n.t('error.connection-to-server-refused');
            }