The code property identifies the type of error; the endpoint property
identifies the endpoint that returned the error (for example PLACES_DETAILS). Since
MapsNetworkError is a subclass of Error, other properties including
name and message are also available.
The following snippet shows the structure of a Maps error message:
The raw error includes everything in the error string; error.message includes the
entire error string excluding error.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);}}// ...}
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 UTC."],[],[],null,["This page describes how to handle errors when using the Maps JavaScript API,\nand the Place class.\n\n\nThe Google Maps JavaScript API uses the following classes for errors:\n\n- [`MapsNetworkError`](/maps/documentation/javascript/reference/errors#MapsNetworkError) represents a network error from a web service (can include [RPCStatus](/maps/documentation/javascript/reference/errors#RPCStatus) errors).\n- [`MapsRequestError`](/maps/documentation/javascript/reference/errors#MapsRequestError) represents a request error from a web service (i.e. the equivalent of a 4xx code in HTTP).\n- [`MapsServerError`](/maps/documentation/javascript/reference/errors#MapsServerError) represents a server-side error from a web service (i.e. the equivalent of a 5xx code in HTTP).\n\nThe `MapsNetworkError`, `MapsRequestError`, and `MapsServerError`\nclasses belong to the [maps core library](/maps/documentation/javascript/reference/library-interfaces#CoreLibrary).\nLearn more about [libraries](/maps/documentation/javascript/libraries).\n| **Note:** Errors returned by the classes listed above comprise only one kind of possible error. It is possible to encounter errors that are not represented by these classes, for example, client-side validation errors, errors related to API keys or quota, and other unexpected errors.\n\nEach of these classes contains the following properties:\n\n- [`code`](/maps/documentation/javascript/reference/errors#MapsNetworkError.code)\n- [`endpoint`](/maps/documentation/javascript/reference/errors#MapsNetworkError.endpoint)\n\nThe `code` property identifies the type of error; the `endpoint` property\nidentifies the endpoint that returned the error (for example `PLACES_DETAILS`). Since\n`MapsNetworkError` is a subclass of `Error`, other properties including\n`name` and `message` are also available.\n\nThe following snippet shows the structure of a Maps error message: \n\n```javascript\n MapsRequestError: PLACES_GET_PLACE: INVALID_ARGUMENT: Error fetching fields: The provided Place ID: ChIJN5Nz71W3j4ARhx5bwpTQEGg**** is not valid.\n [error.name ] [error.endpoint ] [error.code ]\n [error.message ---\u003e ... ]\n \n```\n\nThe raw error includes everything in the error string; `error.message` includes the\nentire error string excluding `error.name`.\n\nThe following snippet demonstrates error handling when using the Place class.\nThis example uses a try/catch block to handle each of the three error types. Similar code can be\nused to handle errors for any Maps JavaScript API class. \n\n```javascript\nasync function getPlaceDetails() {\n const { Place } = await google.maps.importLibrary(\"places\") as google.maps.PlacesLibrary;\n const { MapsNetworkError, MapsRequestError, MapsServerError } = await google.maps.importLibrary(\"core\") as google.maps.CoreLibrary;\n\n // Use place ID to create a new Place instance.\n const place = new Place({\n id: 'ChIJN5Nz71W3j4ARhx5bwpTQEGg****', // Pass a bad Place ID to trigger an error.\n });\n\n // Error handling for fetchFields.\n try {\n // Call fetchFields, passing the desired data fields.\n await place.fetchFields({ fields: ['displayName', 'formattedAddress', 'location'] });\n } catch (error: any) {\n if (error && error instanceof google.maps.MapsRequestError) {\n // HTTP 4xx request error.\n console.error('fetchFields failed: MapsRequestError - check the request parameters', error);\n } else if (error && error instanceof google.maps.MapsServerError) {\n // HTTP 5xx server-side error.\n console.error('fetchFields failed: MapsServerError', error);\n } else if (error && error instanceof google.maps.MapsNetworkError) {\n // Network error.\n console.error('fetchFields failed: MapsNetworkError', error);\n } else {\n console.error('fetchFields failed: An unknown error occurred', error);\n }\n }\n // ...\n}\n```"]]