Skip to content

Consider decoupling service from console functions #421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jeroenheijmans opened this issue Sep 6, 2018 · 2 comments
Closed

Consider decoupling service from console functions #421

jeroenheijmans opened this issue Sep 6, 2018 · 2 comments

Comments

@jeroenheijmans
Copy link
Collaborator

The oauth-service.ts file has many console.error and console.warn calls. This is possibly great default behavior, but I'd like to be able to overwrite it for two main reasons:

  1. Sometimes I disagree with the error. Put differently, I'm working on a case currently where the console.error is not an error but an expected exceptional situation which I will handle myself.
  2. In production I'd prefer to keep my console clean of anything but critical stuff, and have a logging service to catch all the other stuff

For those reasons I propose we decouple the OAuthService from console functions, for example similar to how you can inject a different OAuthStorage.

Some (pseudo)code:

export interface OAuthLoggingAdapter {
  warn(message?: any, ...optionalParams: any[]): void;
  error(message?: any, ...optionalParams: any[]): void;
}

and default:

{ provide: OAuthLoggingAdapter, useValue: console },

then the service can rely on OAuthLoggingAdapter being injected (replacing all console.warn/.error calls), and users of the library can themselves provide a different implementation, if they like.

I'm happy to write a PR for this, but before I do so I'd love to get some feedback on whether it's a good idea and whether the PR has a chance of being accepted.

@manfredsteyer
Copy link
Owner

Great idea. Care for a PR? I'm preparing a new version soon.

jeroenheijmans added a commit to jeroenheijmans/angular-oauth2-oidc that referenced this issue Sep 15, 2018
@jeroenheijmans
Copy link
Collaborator Author

I've created PR #427 for this, trying to stick closely to the conventions set in the library, taking OAuthStorage's implementation as an example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants