Types & Errors

Request And Response Types

The SDK exports all request and response types as TypeScript interfaces. Simply import them using the MMG namespace:

1import { MMG } from "mobile-money-sdk";
2
3const request: MMG.PostECommerceLoginMerRequest = {
4 // ... your request data
5};

Exception Handling

When the API returns a non-success status code (4xx or 5xx response), a subclass of MMGError will be thrown. You can catch these errors to inspect the status code and raw response.

1import { MMGError } from "mobile-money-sdk";
2
3try {
4 await client.authentication.loginResourceTokenApi(...);
5} catch (err) {
6 if (err instanceof MMGError) {
7 console.log(err.statusCode);
8 console.log(err.message);
9 console.log(err.body);
10 console.log(err.rawResponse);
11 }
12}