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.
| Property | Type | Description |
|---|---|---|
message | string | Human-readable error message |
name | "RMPError" | Error name |
HttpError #
Thrown when the server returns a non-2xx HTTP status code.
| Property | Type | Description |
|---|---|---|
status_code | number | HTTP status code |
url | string | The URL that was requested |
body | string | undefined | Response body text |
ParsingError #
Thrown when the response can't be parsed or when the entity doesn't exist.
| Property | Type | Description |
|---|---|---|
message | string | What went wrong |
RateLimitError #
Thrown when the local token-bucket rate limiter blocks a request.
| Property | Type | Description |
|---|---|---|
message | string | Defaults to "Local rate limit exceeded" |
RetryError #
Thrown when all retry attempts are exhausted.
| Property | Type | Description |
|---|---|---|
last_error | Error | The last error that caused the final failure |
RMPAPIError #
Thrown when the RMP GraphQL API returns an errors array in the response body.
| Property | Type | Description |
|---|---|---|
message | string | Combined error message |
details | unknown | Raw error payload from the API |
ConfigurationError #
Thrown when client configuration is invalid.
| Property | Type | Description |
|---|---|---|
message | string | What's wrong with the configuration |