Skip to main content

๐Ÿšจ 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