Skip to content

Commit

Permalink
fix: waiter validation throws a proper error object
Browse files Browse the repository at this point in the history
  • Loading branch information
alexforsyth committed Dec 23, 2020
1 parent efb0f0e commit ca7b5db
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
14 changes: 7 additions & 7 deletions packages/util-waiter/src/utils/validate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ describe(validateWaiterOptions.name, () => {
validateWaiterOptions(waiterOptions);
expect(1).toBe("SHOULD NOT GET HERE");
} catch (e) {
expect(e).toBe(
"WaiterConfiguration.maxDelay [120] must be greater than WaiterConfiguration.minDelay [200] for this waiter"
expect(e.toString()).toBe(
"Error: WaiterConfiguration.maxDelay [120] must be greater than WaiterConfiguration.minDelay [200] for this waiter"
);
done();
}
Expand All @@ -59,7 +59,7 @@ describe(validateWaiterOptions.name, () => {
try {
validateWaiterOptions(waiterOptions);
} catch (e) {
expect(e).toBe("WaiterConfiguration.maxWaitTime must be greater than 0");
expect(e.toString()).toBe("Error: WaiterConfiguration.maxWaitTime must be greater than 0");
done();
}
});
Expand All @@ -70,8 +70,8 @@ describe(validateWaiterOptions.name, () => {
try {
validateWaiterOptions(waiterOptions);
} catch (e) {
expect(e).toBe(
"WaiterConfiguration.maxWaitTime [150] must be greater than WaiterConfiguration.minDelay [200] for this waiter"
expect(e.toString()).toBe(
"Error: WaiterConfiguration.maxWaitTime [150] must be greater than WaiterConfiguration.minDelay [200] for this waiter"
);
done();
}
Expand All @@ -83,8 +83,8 @@ describe(validateWaiterOptions.name, () => {
try {
validateWaiterOptions(waiterOptions);
} catch (e) {
expect(e).toBe(
"WaiterConfiguration.maxWaitTime [200] must be greater than WaiterConfiguration.minDelay [200] for this waiter"
expect(e.toString()).toBe(
"Error: WaiterConfiguration.maxWaitTime [200] must be greater than WaiterConfiguration.minDelay [200] for this waiter"
);
}
});
Expand Down
14 changes: 9 additions & 5 deletions packages/util-waiter/src/utils/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ import { WaiterOptions } from "../waiter";
*/
export const validateWaiterOptions = <Client>(options: WaiterOptions<Client>): void => {
if (options.maxWaitTime < 1) {
throw `WaiterConfiguration.maxWaitTime must be greater than 0`;
throw new Error(`WaiterConfiguration.maxWaitTime must be greater than 0`);
} else if (options.minDelay < 1) {
throw `WaiterConfiguration.minDelay must be greater than 0`;
throw new Error(`WaiterConfiguration.minDelay must be greater than 0`);
} else if (options.maxDelay < 1) {
throw `WaiterConfiguration.maxDelay must be greater than 0`;
throw new Error(`WaiterConfiguration.maxDelay must be greater than 0`);
} else if (options.maxWaitTime <= options.minDelay) {
throw `WaiterConfiguration.maxWaitTime [${options.maxWaitTime}] must be greater than WaiterConfiguration.minDelay [${options.minDelay}] for this waiter`;
throw new Error(
`WaiterConfiguration.maxWaitTime [${options.maxWaitTime}] must be greater than WaiterConfiguration.minDelay [${options.minDelay}] for this waiter`
);
} else if (options.maxDelay < options.minDelay) {
throw `WaiterConfiguration.maxDelay [${options.maxDelay}] must be greater than WaiterConfiguration.minDelay [${options.minDelay}] for this waiter`;
throw new Error(
`WaiterConfiguration.maxDelay [${options.maxDelay}] must be greater than WaiterConfiguration.minDelay [${options.minDelay}] for this waiter`
);
}
};

0 comments on commit ca7b5db

Please sign in to comment.