More logical error handling

This commit is contained in:
James Barnsley
2017-10-26 19:26:38 +13:00
parent 563ac34cee
commit 47fe20bcd7
4 changed files with 97 additions and 79 deletions

View File

@ -43,10 +43,11 @@ export function startSearch(search_type, query, only_mopidy = false){
}
}
export function handleException(message, data = {}){
export function handleException(message, data = {}, description = null){
return {
type: 'HANDLE_EXCEPTION',
message: message,
description: description,
data: data
}
}

View File

@ -22,12 +22,15 @@ const CoreMiddleware = (function(){
// Construct meaningful message and description
var message = action.message;
var description = null;
if (action.data.xhr && action.data.xhr.responseText){
if (action.description){
var description = action.description;
} else if (action.data.xhr && action.data.xhr.responseText){
var xhr_response = JSON.parse(action.data.xhr.responseText);
if (xhr_response.error && xhr_response.error.message){
description = xhr_response.error.message;
var description = xhr_response.error.message;
}
} else {
var description = null;
}
// Prepare a summary dump of our state
@ -77,7 +80,7 @@ const CoreMiddleware = (function(){
ReactGA.event({
category: "Error",
action: message,
label: (description ? description : "No description"),
label: description,
nonInteraction: true
});
@ -88,7 +91,7 @@ const CoreMiddleware = (function(){
null,
description
));
console.error(action.message, data);
console.error(message, description, data);
break;
case 'CORE_START_SERVICES':