Skip to main content

Error Handling

The SDK provides typed error classes for different failure scenarios.

Error Hierarchy

All SDK errors extend from QumraError, making it easy to catch and handle specific error types.

QumraError (base)
├── QumraAuthError
├── QumraFetchError
└── QumraValidationError

QumraError (Base)

The base error class for all SDK errors. All other error classes extend from this.

class QumraError extends Error {
readonly code: string;
constructor(message: string, code: string);
}
PropertyTypeDescription
codestringMachine-readable error code
messagestringHuman-readable error description

QumraAuthError

Thrown when authentication fails, such as an invalid or expired token, or missing credentials.

PropertyValue
code"AUTH_ERROR"

Common causes:

  • Invalid or expired JWT token
  • Missing API credentials
  • Revoked access token

QumraFetchError

Thrown when an API request to the Qumra platform fails. Includes the HTTP response details for debugging.

class QumraFetchError extends QumraError {
readonly status: number;
readonly statusText: string;
readonly responseBody: string;
}
PropertyTypeDescription
codestringAlways "FETCH_ERROR"
statusnumberHTTP status code (e.g., 404, 500)
statusTextstringHTTP status text (e.g., "Not Found")
responseBodystringRaw response body from the API

QumraValidationError

Thrown by request validation utilities such as bot detection and iframe validation.

PropertyValue
code"VALIDATION_ERROR"

Common causes:

  • Request detected as a bot (validateNotBot)
  • Request not from a valid iframe context (validateIframeRequest)

Complete Error Handling Example

import {
QumraAuthError,
QumraFetchError,
QumraValidationError,
} from "@qumra/app-sdk";
import { authenticate } from "~/qumra.server";

export async function loader({ request }: { request: Request }) {
try {
const { admin } = await authenticate.admin(request);
const data = await admin.graphql(`query { shop { name } }`);
return Response.json(data);
} catch (error) {
if (error instanceof Response) {
// OAuth redirect - return it as-is
return error;
}
if (error instanceof QumraAuthError) {
return Response.json({ error: "Authentication failed" }, { status: 401 });
}
if (error instanceof QumraFetchError) {
return Response.json(
{ error: "API request failed", status: error.status },
{ status: 502 }
);
}
if (error instanceof QumraValidationError) {
return Response.json({ error: "Invalid request" }, { status: 400 });
}
throw error;
}
}
danger

Always check for Response type first. During OAuth redirects, authenticate.admin() throws a Response object that must be returned to the client.