Throw an error when _getProfile doesn't have a matching profile (#1826)
This commit is contained in:
parent
437b588411
commit
d5320c71a6
@ -996,14 +996,27 @@ class Backend {
|
|||||||
_getProfile(optionsContext, useSchema=false) {
|
_getProfile(optionsContext, useSchema=false) {
|
||||||
const options = this._getOptionsFull(useSchema);
|
const options = this._getOptionsFull(useSchema);
|
||||||
const profiles = options.profiles;
|
const profiles = options.profiles;
|
||||||
if (optionsContext.current) {
|
if (!optionsContext.current) {
|
||||||
return profiles[options.profileCurrent];
|
// Specific index
|
||||||
|
const {index} = optionsContext;
|
||||||
|
if (typeof index === 'number') {
|
||||||
|
if (index < 0 || index >= profiles.length) {
|
||||||
|
throw this._createDataError(`Invalid profile index: ${index}`, optionsContext);
|
||||||
}
|
}
|
||||||
if (typeof optionsContext.index === 'number') {
|
return profiles[index];
|
||||||
return profiles[optionsContext.index];
|
|
||||||
}
|
}
|
||||||
|
// From context
|
||||||
const profile = this._getProfileFromContext(options, optionsContext);
|
const profile = this._getProfileFromContext(options, optionsContext);
|
||||||
return profile !== null ? profile : profiles[options.profileCurrent];
|
if (profile !== null) {
|
||||||
|
return profile;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Default
|
||||||
|
const {profileCurrent} = options;
|
||||||
|
if (profileCurrent < 0 || profileCurrent >= profiles.length) {
|
||||||
|
throw this._createDataError(`Invalid current profile index: ${profileCurrent}`, optionsContext);
|
||||||
|
}
|
||||||
|
return profiles[profileCurrent];
|
||||||
}
|
}
|
||||||
|
|
||||||
_getProfileFromContext(options, optionsContext) {
|
_getProfileFromContext(options, optionsContext) {
|
||||||
@ -1030,6 +1043,12 @@ class Backend {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_createDataError(message, data) {
|
||||||
|
const error = new Error(message);
|
||||||
|
error.data = data;
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
_clearProfileConditionsSchemaCache() {
|
_clearProfileConditionsSchemaCache() {
|
||||||
this._profileConditionsSchemaCache = [];
|
this._profileConditionsSchemaCache = [];
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user