Skip to content

Commit

Permalink
feat(Mapping): add tolerant field fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
RWOverdijk committed Nov 13, 2016
1 parent e9608aa commit 6ab210b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,19 @@ export class Mapping<T> {
/**
* Get the options for provided `property` (field).
*
* @param {string} property
* @param {string} property
* @param {boolean} [tolerant] Don't throw an error, but return null
*
* @returns {FieldOptions}
*/
public getField(property: string): FieldOptions {
public getField(property: string, tolerant: boolean = false): FieldOptions {
let field = this.mapping.fetch(`fields.${property}`);

if (!field) {
if (tolerant) {
return null;
}

throw new Error(`Unknown field "${property}" supplied.`);
}

Expand Down

0 comments on commit 6ab210b

Please sign in to comment.