-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from diogofcunha/errors
refactor: 💡started to use dedicated classes for errors
- Loading branch information
Showing
2 changed files
with
42 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
export class NodeNotFoundError extends Error { | ||
constructor(nodeId: string) { | ||
super(`Node ${nodeId} not found`); | ||
} | ||
} | ||
|
||
export enum WeightedGraphEdgeErrorType { | ||
ShouldProvideWeight, | ||
ShouldNotProvideWeight | ||
} | ||
|
||
export class WeightedGraphEdgeError extends Error { | ||
constructor(type: WeightedGraphEdgeErrorType) { | ||
super( | ||
type === WeightedGraphEdgeErrorType.ShouldProvideWeight | ||
? `Can't add an edge to a weighted graph without weight` | ||
: `Can't add an edge to a unweighted graph with weight` | ||
); | ||
} | ||
} | ||
|
||
export class GraphCycleError extends Error { | ||
constructor() { | ||
super(`Graph has a cycle`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters