Skip to content

Commit

Permalink
fix(imports): use Severity.Level
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasBa committed Dec 14, 2021
1 parent 66cbe52 commit 29bb6ad
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 21 deletions.
2 changes: 1 addition & 1 deletion packages/browser/src/integrations/breadcrumbs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ export class Breadcrumbs implements Integration {
{
category: 'fetch',
data: handlerData.fetchData,
level: Severity.Error,
level: 'error',
type: 'http',
},
{
Expand Down
2 changes: 1 addition & 1 deletion packages/hub/src/hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ export class Hub implements HubInterface {
/**
* @inheritDoc
*/
public captureMessage(message: string, level?: Severity, hint?: EventHint): string {
public captureMessage(message: string, level?: Severity.Level, hint?: EventHint): string {
const eventId = (this._lastEventId = uuid4());
let finalHint = hint;

Expand Down
2 changes: 1 addition & 1 deletion packages/hub/src/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class Scope implements ScopeInterface {
protected _fingerprint?: string[];

/** Severity */
protected _level?: Severity;
protected _level?: Severity.Level;

/** Transaction Name */
protected _transactionName?: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/breadcrumb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Severity } from './severity';
/** JSDoc */
export interface Breadcrumb {
type?: string;
level?: Severity;
level?: Severity.Level;
event_id?: string;
category?: string;
message?: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export interface Client<O extends Options = Options> {
* @param scope An optional scope containing event metadata.
* @returns The event id
*/
captureMessage(message: string, level?: Severity, hint?: EventHint, scope?: Scope): string | undefined;
captureMessage(message: string, level?: Severity.Level, hint?: EventHint, scope?: Scope): string | undefined;

/**
* Captures a manually created event and sends it to Sentry.
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface Event {
message?: string;
timestamp?: number;
start_timestamp?: number;
level?: Severity;
level?: Severity.Level;
platform?: string;
logger?: string;
server_name?: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export interface Hub {
* @param hint May contain additional information about the original exception.
* @returns The generated eventId.
*/
captureMessage(message: string, level?: Severity, hint?: EventHint): string;
captureMessage(message: string, level?: Severity.Level, hint?: EventHint): string;

/**
* Captures a manually created event and sends it to Sentry.
Expand Down
4 changes: 2 additions & 2 deletions packages/types/src/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type CaptureContext = Scope | Partial<ScopeContext> | ((scope: Scope) =>
/** JSDocs */
export interface ScopeContext {
user: User;
level: Severity;
level: Severity.Level;
extra: Extras;
contexts: Contexts;
tags: { [key: string]: Primitive };
Expand Down Expand Up @@ -82,7 +82,7 @@ export interface Scope {
* Sets the level on the scope for future events.
* @param level string {@link Severity}
*/
setLevel(level: Severity): this;
setLevel(level: Severity.Level): this;

/**
* Sets the transaction name on the scope for future events.
Expand Down
28 changes: 16 additions & 12 deletions packages/types/src/severity.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
const severity = ['fatal', 'error', 'warning', 'log', 'info', 'debug', 'critical'] as const;
export type Severity = typeof severity[number];
// eslint-disable-next-line @typescript-eslint/no-namespace, import/export
export namespace Severity {
const levels = ['fatal', 'error', 'warning', 'log', 'info', 'debug', 'critical'] as const;

/**
* Converts a string-based level into a {@link Severity}.
*
* @param level string representation of severity
* @returns Severity
*/
export function severityFromString(level: string): Severity {
if (severity.indexOf(level as Severity) === -1) {
return 'log';
export type Level = typeof levels[number];

/**
* Converts a string-based level into a {@link Severity}.
*
* @param level string representation of severity
* @returns Severity
*/
export function fromString(level: string): Level {
if (levels.indexOf(level as Level) === -1) {
return 'log';
}
return level as Level;
}
return level as Severity;
}

0 comments on commit 29bb6ad

Please sign in to comment.