๐จ Core Exceptions
The SDK provides a consistent exception model for handling errors returned by the Google Maps API.
Instead of dealing with raw HTTP errors or JSON responses, errors are mapped into strongly-typed .NET exceptions.
๐งพ MapsApiExceptionโ
Base exception for all errors produced by the SDK.
public class MapsApiException : Exception {
public string? Status { get; }
public string? RawResponse { get; }
}
โ๏ธ Propertiesโ
Statusโ API status code (if available)RawResponseโ raw API response (useful for debugging)
๐ข When it happensโ
- General SDK errors
๐ง Notesโ
- All SDK exceptions inherit from this class
- Contains additional API context beyond standard exceptions
- Useful for logging and debugging
๐ MapsApiAuthExceptionโ
Represents authentication errors.
public class MapsApiAuthException : MapsApiException
๐ข When it happensโ
- Invalid API key
- Missing API key
- Insufficient permissions
โ ๏ธ MapsInvalidRequestExceptionโ
Represents invalid request errors.
public class MapsInvalidRequestException : MapsApiException
๐ข When it happensโ
- Missing required parameters
- Invalid parameter values
๐ MapsNotFoundExceptionโ
Represents resource-not-found errors.
public class MapsNotFoundException : MapsApiException
๐ข When it happensโ
- Requested resource does not exist
- Invalid place ID, route, etc.
๐ฆ MapsRateLimitExceptionโ
Represents rate limit errors.
public class MapsRateLimitException : MapsApiException
๐ข When it happensโ
- Too many requests in a short period
- API quota exceeded
โก Exampleโ
try {
var result = await places.Search.SearchByTextAsync("coffee");
}
catch (MapsApiAuthException ex) {
// Handle invalid API key
}
catch (MapsRateLimitException ex) {
// Retry or backoff
}
catch (MapsApiException ex) {
// Generic API error
}
๐ง Design Notesโ
- Exceptions are specific and predictable
- Encourages granular error handling
- Avoids exposing raw API responses directly
- Still allows access to raw data when needed