Skip to content

Commit

Permalink
Improve error handling in getServiceClassAuthOrigin
Browse files Browse the repository at this point in the history
Enhance reliability by throwing a TypeError when a service key definition is missing.
It's common for a key to be missing and might require the developer that writes tests to provide a fake on that fits the examples used.

Key changes:
- Added a check for missing service key definitions in getServiceClassAuthOrigin.
- Throws a TypeError with a clear message if the key is not found.
- Guides devs to use an override if needed which is often.
  • Loading branch information
jNullj committed Mar 9, 2024
1 parent 1c15782 commit a713669
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions services/test-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ function getServiceClassAuthOrigin(serviceClass, authOverride, configOverride) {
return serviceClass.auth.authorizedOrigins
} else {
const mergedConfig = _.merge(runnerConfig, configOverride)
if (!mergedConfig.public.services[auth.serviceKey]) {
throw new TypeError(
`Missing service key defenition for ${auth.serviceKey}: Use an override if applicable.`,
)
}
return [mergedConfig.public.services[auth.serviceKey].authorizedOrigins]
}
}
Expand Down

0 comments on commit a713669

Please sign in to comment.