More helpful exceptions in itemFields methods when given an invalid fieldID or a fieldID with no associated itemTypes (neither should actually happen once things are set up right)
This commit is contained in:
parent
1d9fa85c15
commit
d22d77fedf
1 changed files with 24 additions and 0 deletions
|
@ -1536,6 +1536,13 @@ Scholar.ItemFields = new function(){
|
||||||
if (!_fields.length){
|
if (!_fields.length){
|
||||||
_loadFields();
|
_loadFields();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_fieldCheck(fieldID);
|
||||||
|
|
||||||
|
if (!_fields[fieldID]['itemTypes']){
|
||||||
|
throw('No associated itemTypes for fieldID ' + fieldID);
|
||||||
|
}
|
||||||
|
|
||||||
return !!_fields[fieldID]['itemTypes'][itemTypeID];
|
return !!_fields[fieldID]['itemTypes'][itemTypeID];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1544,6 +1551,9 @@ Scholar.ItemFields = new function(){
|
||||||
if (!_fields.length){
|
if (!_fields.length){
|
||||||
_loadFields();
|
_loadFields();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_fieldCheck(fieldID);
|
||||||
|
|
||||||
var ffid = _fields[fieldID]['formatID'];
|
var ffid = _fields[fieldID]['formatID'];
|
||||||
return _fieldFormats[ffid] ? _fieldFormats[ffid]['isInteger'] : false;
|
return _fieldFormats[ffid] ? _fieldFormats[ffid]['isInteger'] : false;
|
||||||
}
|
}
|
||||||
|
@ -1565,6 +1575,20 @@ Scholar.ItemFields = new function(){
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether a fieldID is valid, throwing an exception if not
|
||||||
|
* (since it should never actually happen)
|
||||||
|
**/
|
||||||
|
function _fieldCheck(fieldID){
|
||||||
|
if (!_fields.length){
|
||||||
|
_loadFields();
|
||||||
|
}
|
||||||
|
if (typeof _fields[fieldID]=='undefined'){
|
||||||
|
throw('Invalid fieldID ' + fieldID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns hash array of itemTypeIDs for which a given field is valid
|
* Returns hash array of itemTypeIDs for which a given field is valid
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue