Skip to content

Commit

Permalink
add logger options
Browse files Browse the repository at this point in the history
  • Loading branch information
AndriiAndreiev committed Aug 5, 2024
1 parent e7e2aa7 commit 4732eb3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/node/src/lib/ReadMe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { log } from './log';
import { buildSetupView } from './setup-readme-view';
import { testVerifyWebhook } from './test-verify-webhook';
import verifyWebhook from './verify-webhook';
import { logger } from './logger';

interface BasicAuthObject {
pass: string;
Expand Down Expand Up @@ -158,6 +159,7 @@ export default class ReadMe {
}).then(r => r.json() as Promise<ReadMeVersion[]>);
} catch (e) {
// TODO: Maybe send this to sentry?
logger.error({ err: e, message: 'Error fetching readme data' })
if (e.status === 401) {
console.error('Invalid ReadMe API key. Contact [email protected] for help!');
console.error(e.data);
Expand Down
5 changes: 5 additions & 0 deletions packages/node/src/lib/construct-payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ export interface LogOptions {
* @deprecated use `allowList` instead
*/
whitelist?: string[];

/**
* If true, the errors will be logged in console.
*/
logger?: boolean;
}

export interface PayloadData {
Expand Down
2 changes: 1 addition & 1 deletion packages/node/src/lib/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function doSend(readmeApiKey: string, options: Options) {
// Make the log call
metricsAPICall(readmeApiKey, json, options).catch(e => {
// Silently discard errors and timeouts.
if (options.development) {
if (options.development && options.logger) {
logger.error(e);
}
});
Expand Down

0 comments on commit 4732eb3

Please sign in to comment.