Skip to content

Commit

Permalink
Handle Internal Server Errors (#8562)
Browse files Browse the repository at this point in the history
Signed-off-by: Suchit Sahoo <[email protected]>
  • Loading branch information
LDrago27 authored Oct 14, 2024
1 parent d4be718 commit 2be8d04
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/plugins/data/server/dql_telemetry/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export function registerDqlTelemetryRoute(
},
async (context, request, response) => {
const [{ savedObjects }] = await getStartServices();
const internalRepository = savedObjects.createScopedRepository(request);

const {
body: { opt_in: optIn },
Expand All @@ -56,11 +55,12 @@ export function registerDqlTelemetryRoute(
const counterName = optIn ? 'optInCount' : 'optOutCount';

try {
const internalRepository = savedObjects.createScopedRepository(request);
await internalRepository.incrementCounter('dql-telemetry', 'dql-telemetry', counterName);
} catch (error) {
logger.warn(`Unable to increment counter: ${error}`);
return response.customError({
statusCode: error.status,
statusCode: error.status || 403,
body: {
message: 'Something went wrong',
attributes: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ export const timeSeriesVisualizationClientWrapper: SavedObjectsClientWrapperFact
}

const tsvbAttributes = attributes as T & { visState: string };
const visState = JSON.parse(tsvbAttributes.visState);
let visState;
try {
visState = JSON.parse(tsvbAttributes.visState);
} catch (ex) {
throw SavedObjectsErrorHelpers.createUnsupportedTypeError(type);
}

if (visState.type !== 'metrics' || !visState.params) {
return await wrapperOptions.client.create(type, attributes, options);
Expand Down

0 comments on commit 2be8d04

Please sign in to comment.