Skip to content

Commit

Permalink
Handle Internal Server Errors
Browse files Browse the repository at this point in the history
Signed-off-by: Suchit Sahoo <[email protected]>
  • Loading branch information
LDrago27 committed Oct 11, 2024
1 parent 9eae148 commit d75b02e
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);

Check warning on line 58 in src/plugins/data/server/dql_telemetry/route.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/server/dql_telemetry/route.ts#L58

Added line #L58 was not covered by tests
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);

Check warning on line 39 in src/plugins/vis_type_timeseries/server/lib/timeseries_visualization_client_wrapper.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/vis_type_timeseries/server/lib/timeseries_visualization_client_wrapper.ts#L39

Added line #L39 was not covered by tests
}

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

0 comments on commit d75b02e

Please sign in to comment.