Errors and error handling
Overview of FansUnited JS SDK errors and error handling
Fans United JS SDK shares two types of error handling - default and standard. There are situations where SDK returns additional errors for different cases such as - validations, invalid JWT token and etc.
Let's categorized errors by exploring all different cases:
Default errors
Default errors are throwed by default from JS SDK. Fans United JS SDK wraps the errors from API ones in FansUnitedSdkFetchException. Most of the errors are instances of FansUnitedSdkFetchException
class.
FansUnitedSdkFetchException declaration:
interface DefaultFansUnitedExceptionInterface {
error: StandardFansUnitedExceptionInterface;
}
interface StandardFansUnitedExceptionInterface {
code: number;
status: string;
message: string;
}
class FansUnitedSdkFetchException {
data: DefaultFansUnitedExceptionInterface;
status: number;
statusText: string;
headers: Header;
errorMessage: () {
return this.data.error.message;
};
}
Examples:
400 - Bad Request
- The request was unacceptable, often due to missing, wrong or empty parameter.
{
data: {
error: {
code: 400,
message: "Invalid client ID is provided.",
status: "invalid_client_id"
}
},
status: 400,
statusText: "",
headers: {
"cache-control": "no-cache",
"content-length": "94",
"content-type": "application/json;charset=UTF-8"
}
}
- SDK throws own 400 exceptions for the following scenarios:
- sdk.loyalty.getHighestSuccessRate() invalid market is provided (throws object).
Example:{ code: 400, status: "INVALID_MARKET", message: "The market 'ADVANCER_CORECT_SCORE_HT' is not supported from Fans United. For more information please visit our documentation: https://docs.fansunitedmedia.com/docs/predictor-operations#make-football-prediction" }
- Maximum filter limit (50) is exceeded when fetching games (throws object).
Example:{ code: 400, status: "EXCEEDED_LENGTH", message: "Maximum limit for filtering games is 50 or less." }
- When calling sdk.predictor.makeFootballPrediction() SDK throws message or object in the following cases:
- No matchId argument is provided (throws message).
Example:"Match id is invalid!"
- No playerId argument is provided when the market is related to player one (throws message).
Example:"Player id is invalid!"
- Invalid prediction value is provided for the provided market (throws object).
Example:{ code: 400, status: "INVALID_PREDICTION", message: "The prediction '1' is invalid for market 'DOUBLE_CHANCE'. Please check again have you passed appropriate prediction model. For more information please visit our documentation: https://docs.fansunitedmedia.com/sdks/js/match.quiz#gamerelatedoperations" }
- Invalid market (not supported from FansUnited) (throws object).
Example:{ code: 400, status: "INVALID_MARKET", message: "The market 'ADVANCER_CORECT_SCORE_HT' is not supported from Fans United. For more information please visit our documentation: https://docs.fansunitedmedia.com/docs/predictor-operations#make-football-prediction" }
- No matchId argument is provided (throws message).
- When calling sdk.topX.play() or sdk.matchQuiz.play() SDK throws object in the following cases:
- Invalid market is provided for Top X game (only CORRECT_SCORE and ADVANCED_CORRECT_SCORE are supported).
Example:{ code: 400, status: "INVALID_MARKET", message: "The market 'FT_1X2' is not valid for Top X game. The only available markets are CORRECT_SCORE and ADVANCED_CORRECT_SCORE." }
- Fields are missing from the provided argument.
Example:{ code: 400, status: "INVALID_FIELD", message: "The following field/s is/are missing from fixtures: 'matchId, prediction'. For more information please visit our documentation: https://docs.fansunitedmedia.com/docs/predictor-operations#make-football-prediction" }
- Invalid type is provided for tiebreaker (sdk.topX.play() argument), goldenGoal (for tiebreaker), prediction in every fixture, playerId for player markets
Example:{ code: 400, status: "INVALID_TYPE", message: "The field goldenGoal has incorrect type. The correct type is number" }
- Invalid market is provided for Top X game (only CORRECT_SCORE and ADVANCED_CORRECT_SCORE are supported).
- sdk.loyalty.getHighestSuccessRate() invalid market is provided (throws object).
401 - Unauthorized
- Invalid JWT token.
{
data: {
error: {
code: 401,
status: "invalid_token",
message: "Invalid JWT token is provided"
}
},
status: 401,
statusText: "Invalid token specified: Cannot read properties of undefined (reading 'replace')",
headers: {}
}
- Expired JWT token is provided.
N.B. JS SDK makes additional request the first time when an expired JWT token is provided. In the second attempt it will use again the getIdToken() from authProvider implementation in SDK configuration. More information here.
{
data: {
error: {
code: 401,
status: "invalid_token",
message: "The provided JWT token is expired"
}
},
status: 401,
statusText: "",
headers: {}
}
When invalid apiKey is provided in SDK configuration a CORS error will appear in the browser.
404 - Not Found
The requested resource doesn't exist.
{
data: {
error: {
code: 404,
status: "no_clients_found_for_user",
message: "No clients found for this user"
}
},
status: 404,
statusText: "",
headers: {}
}
500 - Internal Server Error
Indicates that the server encountered an unexpected condition that prevented it from fulfilling the request.
{
data: {
error: {
code: 500,
status: "failed_to_delete_user",
message: "Failed to delete user"
}
},
status: 500,
statusText: "",
headers: {}
}
Standard errors
errorHandlingMode
property in SDK configuration is set to "standard". All throwed error will be returned as a same model from FansUnited SDK.
Examples:
400 - Bad Request
The request was unacceptable, often due to missing, wrong or empty parameter.
{
error: {
code: 400,
status: "no_client_found",
message: "No client found with the given id"
}
}
401 - Unauthorized
- Invalid JWT token is provided.
{
error: {
code: 401,
status: "invalid_token",
message: "Invalid JWT token is provided"
}
}
- Expired JWT token is provided.
N.B. JS SDK makes additional request the first time when an expired JWT token is provided. In the second attempt it will use again the getIdToken() from authProvider implementation in SDK configuration. More information here.
{
error: {
code: 401,
status: "unauthorized",
message: "The provided JWT token is expired"
}
}
When invalid apiKey is provided in SDK configuration a CORS error will appear in the browser.
404 - Not Found
The requested resource doesn't exist.
{
error: {
code: 404,
status: "no_clients_found_for_user",
message: "No clients found for this user"
}
}
500 - Internal Server Error
Indicates that the server encountered an unexpected condition that prevented it from fulfilling the request.
{
error: {
code: 500,
status: "failed_to_delete_user",
message: "Failed to delete user"
}
}
Updated 11 months ago