Skip to content

Real-time dashboard for monitoring global news, markets, and geopolitical events

TypeScript

Add custom error classes for service layer

Sean Thielen-Esparzaa230a8f1708a
diff --git a/js/services/errors.js b/js/services/errors.js
new file mode 100644
index 0000000..f8f19f1
--- /dev/null
+++ b/js/services/errors.js
@@ -0,0 +1,34 @@
+// errors.js - Custom error classes for service layer
+
+export class ServiceError extends Error {
+ constructor(message, serviceId = null) {
+ super(message);
+ this.name = 'ServiceError';
+ this.serviceId = serviceId;
+ }
+}
+
+export class NetworkError extends Error {
+ constructor(message, status = null) {
+ super(message);
+ this.name = 'NetworkError';
+ this.status = status;
+ }
+}
+
+export class TimeoutError extends Error {
+ constructor(url, timeout = null) {
+ super(`Request timed out: ${url}`);
+ this.name = 'TimeoutError';
+ this.url = url;
+ this.timeout = timeout;
+ }
+}
+
+export class CircuitOpenError extends Error {
+ constructor(serviceId) {
+ super(`Circuit breaker open for service: ${serviceId}`);
+ this.name = 'CircuitOpenError';
+ this.serviceId = serviceId;
+ }
+}