fix readonly error (#91104)

This commit is contained in:
Joe Reuter 2021-02-16 13:46:02 +01:00 committed by GitHub
parent 2ef468ef82
commit 7f1071149d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

View file

@ -98,6 +98,12 @@ export class LensReportManager {
this.write();
} catch (e) {
// Silent error because events will be reported during the next timer
// If posting stats is forbidden for the current user, stop attempting to send them,
// but keep them in storage to push in case the user logs in with sufficient permissions at some point.
if (e.response && e.response.status === 403) {
this.stop();
}
}
}
}

View file

@ -9,6 +9,7 @@ import Boom from '@hapi/boom';
import { errors } from '@elastic/elasticsearch';
import { CoreSetup } from 'src/core/server';
import { schema } from '@kbn/config-schema';
import { SavedObjectsErrorHelpers } from '../../../../../src/core/server';
import { BASE_API_URL } from '../../common';
import { PluginStartContract } from '../plugin';
@ -73,6 +74,9 @@ export async function initLensUsageRoute(setup: CoreSetup<PluginStartContract>)
return res.ok({ body: {} });
} catch (e) {
if (SavedObjectsErrorHelpers.isForbiddenError(e)) {
return res.forbidden();
}
if (e instanceof errors.ResponseError && e.statusCode === 404) {
return res.notFound();
}