mirror of
				https://gitlab.nic.cz/turris/reforis/foris-js.git
				synced 2025-11-03 23:00:31 +01:00 
			
		
		
		
	Rethrow unhandled error from API hooks.
This commit is contained in:
		@@ -53,10 +53,11 @@ function createAPIHook(method) {
 | 
			
		||||
                    payload: result.data,
 | 
			
		||||
                });
 | 
			
		||||
            } catch (error) {
 | 
			
		||||
                const errorPayload = getErrorPayload(error);
 | 
			
		||||
                dispatch({
 | 
			
		||||
                    type: API_ACTIONS.FAILURE,
 | 
			
		||||
                    status: error.response && error.response.status,
 | 
			
		||||
                    payload: getErrorPayload(error),
 | 
			
		||||
                    payload: errorPayload,
 | 
			
		||||
                });
 | 
			
		||||
            }
 | 
			
		||||
        }, [urlRoot, contentType]);
 | 
			
		||||
@@ -80,6 +81,12 @@ function APIReducer(state, action) {
 | 
			
		||||
        if (action.status === 403) {
 | 
			
		||||
            window.location.assign(ForisURLs.login);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Not an API error - should be rethrown.
 | 
			
		||||
        if (action.payload && action.payload.stack && action.payload.message) {
 | 
			
		||||
            throw (action.payload);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return {
 | 
			
		||||
            state: API_STATE.ERROR,
 | 
			
		||||
            data: action.payload,
 | 
			
		||||
 
 | 
			
		||||
@@ -65,9 +65,8 @@ export function getErrorPayload(error) {
 | 
			
		||||
    if (error.request) {
 | 
			
		||||
        return _("No response received.");
 | 
			
		||||
    }
 | 
			
		||||
    /* eslint no-console: "off" */
 | 
			
		||||
    console.error(error);
 | 
			
		||||
    return _("An unknown error occurred. Check the console for more info.");
 | 
			
		||||
    // Return original error because it's not directly related to API request/response.
 | 
			
		||||
    return error;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function getJSONErrorMessage(error) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user