import { schema , ValidationError } from '@osd/config-schema' ; import { IRouter } from '../../http' ; import { SavedObjectsErrorHelpers } from '../../saved_objects' ; import { CannotOverrideError } from '../ui_settings_errors' ; const validate = { body : schema . object ( { changes : schema . object ( { } , { unknowns : 'allow' } ) , } ) , } ; export function registerSetManyRoute ( router ) { router . post ( { path : '/api/opensearch-dashboards/settings' , validate } , async ( context , request , response ) => { try { const uiSettingsClient = context . core . uiSettings . client ; const { changes } = request . body ; await uiSettingsClient . setMany ( changes ) ; return response . ok ( { body : { settings : await uiSettingsClient . getUserProvided ( ) , } , } ) ; } catch ( error ) { if ( SavedObjectsErrorHelpers . isSavedObjectsClientError ( error ) ) { return response . customError ( { body : error , statusCode : error . output . statusCode , } ) ; } if ( error instanceof CannotOverrideError || error instanceof ValidationError ) { return response . badRequest ( { body : error } ) ; } throw error ; } } ) ; }