Errors

All client-specific errors extend RMPError, which extends Error. Use instanceof to distinguish between error types.

import { RMPError, HttpError, ParsingError, RateLimitError, RetryError, RMPAPIError, ConfigurationError } from "ratemyprofessors-client";

Catching Errors #

try {
  const prof = await client.getProfessor(id);
} catch (e) {
  if (e instanceof ParsingError) console.error("Not found:", e.message);
  else if (e instanceof HttpError) console.error("HTTP", e.status_code, e.url);
  else if (e instanceof RetryError) console.error("Gave up:", e.last_error.message);
  else if (e instanceof RateLimitError) console.error("Too many requests:", e.message);
  else if (e instanceof RMPAPIError) console.error("API error:", e.message, e.details);
  else throw e;
}

RMPError #

Base class for all client errors.

PropertyTypeDescription
messagestringHuman-readable error message
name"RMPError"Error name

HttpError #

Thrown when the server returns a non-2xx HTTP status code.

PropertyTypeDescription
status_codenumberHTTP status code
urlstringThe URL that was requested
bodystring | undefinedResponse body text

ParsingError #

Thrown when the response can't be parsed or when the entity doesn't exist.

PropertyTypeDescription
messagestringWhat went wrong

RateLimitError #

Thrown when the local token-bucket rate limiter blocks a request.

PropertyTypeDescription
messagestringDefaults to "Local rate limit exceeded"

RetryError #

Thrown when all retry attempts are exhausted.

PropertyTypeDescription
last_errorErrorThe last error that caused the final failure

RMPAPIError #

Thrown when the RMP GraphQL API returns an errors array in the response body.

PropertyTypeDescription
messagestringCombined error message
detailsunknownRaw error payload from the API

ConfigurationError #

Thrown when client configuration is invalid.

PropertyTypeDescription
messagestringWhat's wrong with the configuration