Skip to content

Commit

Permalink
🔧 Make Timelion server send error details to client
Browse files Browse the repository at this point in the history
  • Loading branch information
dej611 committed Sep 21, 2021
1 parent 4681a80 commit e82616a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export function getTimelionRequestHandler({
const err = new Error(
`${i18n.translate('timelion.requestHandlerErrorTitle', {
defaultMessage: 'Timelion request error',
})}: ${e.body.title} ${e.body.message}`
})}:${e.body.title ? ' ' + e.body.title : ''} ${e.body.message}`
);
err.stack = e.stack;
throw err;
Expand Down
10 changes: 9 additions & 1 deletion src/plugins/vis_types/timelion/server/handlers/chain_runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@ export default function chainRunner(tlConfig) {
let sheet;

function throwWithCell(cell, exception) {
throw new Error(' in cell #' + (cell + 1) + ': ' + exception.message);
throw new Error(
i18n.translate('timelion.serverSideErrors.errorInCell', {
defaultMessage: ' in cell #{number}: {message}',
values: {
number: cell + 1,
message: exception.message,
},
})
);
}

// Invokes a modifier function, resolving arguments into series as needed
Expand Down
21 changes: 12 additions & 9 deletions src/plugins/vis_types/timelion/server/routes/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,18 @@ export function runRoute(
allowedGraphiteUrls: configManager.getGraphiteUrls(),
esShardTimeout: configManager.getEsShardTimeout(),
});
const chainRunner = chainRunnerFn(tlConfig);
const sheet = await Bluebird.all(chainRunner.processRequest(request.body));

return response.ok({
body: {
sheet,
stats: chainRunner.getStats(),
},
});
try {
const chainRunner = chainRunnerFn(tlConfig);
const sheet = await Bluebird.all(chainRunner.processRequest(request.body));
return response.ok({
body: {
sheet,
stats: chainRunner.getStats(),
},
});
} catch (e) {
return response.badRequest({ body: { message: e.message } });
}
})
);
}

0 comments on commit e82616a

Please sign in to comment.