Skip to content

Error Handling ​

All errors thrown by this library extend ZmanimError, so you can catch them in a hierarchy.

Error Classes ​

Error ClassWhen It's Thrown
ZmanimNetworkErrorfetch fails, or HTTP status is not 2xx
ZmanimParseErrorJSON parsing fails, or response is missing required fields
ZmanimErrorBase class for both of the above

Catching Errors ​

ts
import {
  fetchZmanim,
  ZmanimError,
  ZmanimNetworkError,
  ZmanimParseError,
} from "chabad-org-zmanim";

try {
  const result = await fetchZmanim({
    locationId: 11213,
    locationType: 2,
    date: new Date(),
  });
} catch (err) {
  if (err instanceof ZmanimNetworkError) {
    // Network failure or bad HTTP status
    console.error("Network error:", err.message);
    console.error("Status code:", err.statusCode); // e.g. 404, 500
  } else if (err instanceof ZmanimParseError) {
    // Response wasn't valid JSON or was missing fields
    console.error("Parse error:", err.message);
  } else if (err instanceof ZmanimError) {
    // Catch-all for any zmanim error
    console.error("Zmanim error:", err.message);
  }
}

Error Properties ​

ZmanimError ​

PropertyTypeDescription
messagestringHuman-readable error message
causeunknownThe original error that caused this one
namestringAlways "ZmanimError"

ZmanimNetworkError ​

Extends ZmanimError with:

PropertyTypeDescription
statusCodenumber | undefinedHTTP status code (if available)

ZmanimParseError ​

Same shape as ZmanimError. Thrown when:

  • res.json() fails (malformed JSON)
  • The response is missing the Days array

Unofficial client. Not affiliated with or endorsed by Chabad.org.