Make Airbrake config optional in dev
Signed-off-by: Karan Shah <karan.shah@simplybusiness.co.uk>
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { Config } from '@backstage/config';
|
||||
import * as winston from 'winston';
|
||||
|
||||
/**
|
||||
* The configuration needed for the airbrake-backend plugin
|
||||
@@ -33,9 +34,27 @@ export interface AirbrakeConfig {
|
||||
* @public
|
||||
*
|
||||
* @param config - The config object to extract from
|
||||
* @param logger - THe logger object
|
||||
*/
|
||||
export function extractAirbrakeConfig(config: Config): AirbrakeConfig {
|
||||
return {
|
||||
apiKey: config.getString('airbrake.apiKey'),
|
||||
};
|
||||
export function extractAirbrakeConfig(
|
||||
config: Config,
|
||||
logger: winston.Logger,
|
||||
): AirbrakeConfig {
|
||||
try {
|
||||
return {
|
||||
apiKey: config.getString('airbrake.apiKey'),
|
||||
};
|
||||
} catch (e) {
|
||||
if (process.env.NODE_ENV !== 'development') {
|
||||
throw e;
|
||||
} else {
|
||||
logger.warn(
|
||||
'Airbrake config missing, Airbrake plugin will probably not work',
|
||||
e,
|
||||
);
|
||||
return {
|
||||
apiKey: '',
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ export async function startStandaloneServer(
|
||||
): Promise<Server> {
|
||||
const logger = options.logger.child({ service: 'airbrake-backend' });
|
||||
const config = await loadBackendConfig({ logger, argv: process.argv });
|
||||
const airbrakeConfig = extractAirbrakeConfig(config);
|
||||
const airbrakeConfig = extractAirbrakeConfig(config, logger);
|
||||
logger.debug('Starting application server...');
|
||||
const router = await createRouter({
|
||||
logger,
|
||||
|
||||
Reference in New Issue
Block a user