Error Handling Stay organized with collections Save and categorize content based on your preferences.
This page describes how to handle errors when using the Maps JavaScript API, and the Place class.
The Google Maps JavaScript API uses the following classes for errors:
MapsNetworkError
represents a network error from a web service (can includeRPCStatus errors).MapsRequestError
represents a request error from a web service (i.e. the equivalent of a 4xx code in HTTP).MapsServerError
represents a server-side error from a web service (i.e. the equivalent of a 5xx code in HTTP).
TheMapsNetworkError
,MapsRequestError
, andMapsServerError
classes belong to themaps core library. Learn more aboutlibraries.
Each of these classes contains the following properties:
Thecode
property identifies the type of error; theendpoint
property identifies the endpoint that returned the error (for examplePLACES_DETAILS
). SinceMapsNetworkError
is a subclass ofError
, other properties includingname
andmessage
are also available.
The following snippet shows the structure of a Maps error message:
MapsRequestError:PLACES_GET_PLACE:INVALID_ARGUMENT:Errorfetchingfields:TheprovidedPlaceID:ChIJN5Nz71W3j4ARhx5bwpTQEGg****isnotvalid.[error.name][error.endpoint][error.code][error.message--->...]
The raw error includes everything in the error string;error.message
includes the entire error string excludingerror.name
.
The following snippet demonstrates error handling when using the Place class. This example uses a try/catch block to handle each of the three error types. Similar code can be used to handle errors for any Maps JavaScript API class.
asyncfunctiongetPlaceDetails(){const{Place}=awaitgoogle.maps.importLibrary("places")asgoogle.maps.PlacesLibrary;const{MapsNetworkError,MapsRequestError,MapsServerError}=awaitgoogle.maps.importLibrary("core")asgoogle.maps.CoreLibrary;// Use place ID to create a new Place instance.constplace=newPlace({id:'ChIJN5Nz71W3j4ARhx5bwpTQEGg****',// Pass a bad Place ID to trigger an error.});// Error handling for fetchFields.try{// Call fetchFields, passing the desired data fields.awaitplace.fetchFields({fields:['displayName','formattedAddress','location']});}catch(error:any){if(error&&errorinstanceofgoogle.maps.MapsRequestError){// HTTP 4xx request error.console.error('fetchFields failed: MapsRequestError - check the request parameters',error);}elseif(error&&errorinstanceofgoogle.maps.MapsServerError){// HTTP 5xx server-side error.console.error('fetchFields failed: MapsServerError',error);}elseif(error&&errorinstanceofgoogle.maps.MapsNetworkError){// Network error.console.error('fetchFields failed: MapsNetworkError',error);}else{console.error('fetchFields failed: An unknown error occurred',error);}}// ...}
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-10-01 UTC.