Skip to content
Snippets Groups Projects
Select Git revision
  • master default protected
  • L2SS-1914-fix_job_dispatch
  • TMSS-3170
  • TMSS-3167
  • TMSS-3161
  • TMSS-3158-Front-End-Only-Allow-Changing-Again
  • TMSS-3133
  • TMSS-3319-Fix-Templates
  • test-fix-deploy
  • TMSS-3134
  • TMSS-2872
  • defer-state
  • add-custom-monitoring-points
  • TMSS-3101-Front-End-Only
  • TMSS-984-choices
  • SDC-1400-Front-End-Only
  • TMSS-3079-PII
  • TMSS-2936
  • check-for-max-244-subbands
  • TMSS-2927---Front-End-Only-PXII
  • Before-Remove-TMSS
  • LOFAR-Release-4_4_318 protected
  • LOFAR-Release-4_4_317 protected
  • LOFAR-Release-4_4_316 protected
  • LOFAR-Release-4_4_315 protected
  • LOFAR-Release-4_4_314 protected
  • LOFAR-Release-4_4_313 protected
  • LOFAR-Release-4_4_312 protected
  • LOFAR-Release-4_4_311 protected
  • LOFAR-Release-4_4_310 protected
  • LOFAR-Release-4_4_309 protected
  • LOFAR-Release-4_4_308 protected
  • LOFAR-Release-4_4_307 protected
  • LOFAR-Release-4_4_306 protected
  • LOFAR-Release-4_4_304 protected
  • LOFAR-Release-4_4_303 protected
  • LOFAR-Release-4_4_302 protected
  • LOFAR-Release-4_4_301 protected
  • LOFAR-Release-4_4_300 protected
  • LOFAR-Release-4_4_299 protected
40 results

response.handler.js

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    response.handler.js 1.58 KiB
    import React, {useEffect} from "react";
    import axios from "axios";
    import { appGrowl } from './layout/components/AppGrowl';
    import UIConstants from './utils/ui.constants';
    import Auth from './authenticate/auth';
    /**
     * Trigger and validate the response for https status code
     * @param {*} Wrapped 
     * @returns 
     */
    const handleResponse= Wrapped => {
        function HandleResponse(props) {
            useEffect(()=>{
                axios.interceptors.response.use(function (response) {
                    return response;
                }, function (error) {
                    showMessage(error.response);
                    return Promise.reject(error);
                });
            })
            return (
                <Wrapped {...props} />
            );
        }
    
        /**
         * Catch relavent http status code details to show in growl
         * @param {*} response 
         */
        function showMessage(response) {
            const httpStatusMsg = UIConstants.httpStatusMessages[response.status];
            if(httpStatusMsg) {
                appGrowl.show({severity: httpStatusMsg.severity, summary: httpStatusMsg.summary, sticky: httpStatusMsg.sticky, detail: '['+response.status+'] '+JSON.stringify(response.statusText)+ ' ['+httpStatusMsg.detail+']'});
            }   else {
                appGrowl.show({severity: 'error', summary: 'Error', sticky: 'true', detail: '['+response.status+'] '+JSON.stringify(response.statusText)+ '   '+JSON.stringify(response.data)});
            }
            if (response.status === 401) {
                Auth.logout();
                window.location.href = "/login";
            }
        }
        return HandleResponse;
    }
    
    export default handleResponse;