Permalink
Browse files

feat(Mapping): add tolerant field fetching

  • Loading branch information...
RWOverdijk committed Nov 13, 2016
1 parent e9608aa commit 6ab210bc1e8baf56c74abf060ffb1d5bd3ec7bab
Showing with 7 additions and 2 deletions.
  1. +7 −2 src/Mapping.ts
@@ -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.`);
}

0 comments on commit 6ab210b

Please sign in to comment.