Skip to content

Response Model

Every method in the Bigship SDK returns an ApiResponse<T> object. The SDK provides type guard functions to safely narrow the response type.

interface ApiResponse<T> {
status: boolean;
message: string;
status_code: number;
data: T | null;
}
  • status indicates whether the API call succeeded (true / false)
  • data contains the typed payload on success, or null on failure
  • message contains an error message on failure
  • status_code contains the HTTP status code

The SDK exports two type guard functions:

Guard Narrows to When
isSuccessResponse<T>(res) ApiResponse<T> & { status: true; data: T } status === true
isFailedResponse(res) ApiResponse<null> & { status: false; data: null } status === false
import { isSuccessResponse, isFailedResponse } from '@agamya/bigship-sdk';
const response = await client.getProfile();
if (isSuccessResponse(response)) {
// response.data is guaranteed to be non-null
console.log('Profile:', response.data);
}
if (isFailedResponse(response)) {
// response.data is null, response.message has the error
console.error('Error:', response.message);
}
const response = await client.createOrder({ /* ... */ });
if (isFailedResponse(response)) {
throw new Error(response.message ?? 'Order creation failed');
}
// response.data is typed and non-null from here
console.log('Order ID:', response.data?.CustomGlobalOrderId);

Without type guards, you must null-check data manually:

const response = await client.getOrderDetail('311276742');
if (response.data) {
console.log('AWB:', response.data.getOrderDetails.AwbNumber);
}

Type guards are preferred because they provide full type narrowing without manual checks.