Ramadhan Giving Widget Documentation
JavaScript SDK

Error Handling

Handling errors when using the Ramadhan SDK

Error Handling

The SDK shows messages in the button container when something goes wrong.

Missing charity ID

If you call renderButton() without a valid charity ID (e.g. script loaded without ?charityId=... and you didn’t call Ramadhan.init(charityId)), the container will show:

"Ramadhan SDK: charityId is required to load the button."

Missing container

If there is no element with the class ramadhan (and you didn’t pass a container as the second argument), the SDK logs:

"Ramadhan SDK: Container with class 'ramadhan' not found."

Failed to load charity

If the API request to load the charity fails (network error, invalid ID, or API error), the container shows an error message such as:

"Failed to load charity." or the message from the API.

Missing charity website URL

If the charity record has no website/URL for the Ramadhan flow, the container shows:

"Ramadhan SDK: Charity website URL is missing."

Handling in code

The SDK renders these messages inside the container. You can still wrap your init/render in a try/catch if you call Ramadhan.init() and renderButton() in your own code:

try {
  const ramadhan = Ramadhan.init("YOUR_CHARITY_ID", { env: "production" });
  ramadhan.renderButton({ text: "Donate" });
} catch (err) {
  console.error("Ramadhan SDK error:", err.message);
}