Skip to content

Introduction

This package provides the MobyGames class, which facilitates interaction with various endpoints of MobyGames API.

Parameters

To instantiate the MobyGames class, provide your valid MobyGames API key:

ParamsTypeRequiredDescription
keystringYesYour MobyGames API key

Throws exceptions

The package throws exceptions in two key scenarios:

  • key

  • Response.ok

    For more information about the ok property, refer to the official documentation: https://developer.mozilla.org/en-US/docs/Web/API/Response/ok

Best Practices

When making requests with this package, we strongly recommend using try-catch blocks to gracefully handle potential exceptions arising from asynchronous operations. This practice promotes application stability and provides opportunities for informative error messaging.

interface MobyGamesErrorCause {
status: number;
json: {
code: number;
error: string;
message: string;
};
}
try {
const client = new MobyGames('access token');
const { cover_groups } = await client.gamePlatformCovers('120555', '141');
} catch (error: unknown) {
if (error instanceof RangeError) {
// Handle errors based on the response status
if ((error.cause as MobyGamesErrorCause).status === 401) {
console.log('Received Unauthorized response');
}
} else {
console.error('Caught other error type:', error);
}
}