You can manually parse the caught error, but it's not recommended. When catching the exception (that is being thrown in case muteHttpExceptions
is turned off), the error object would be in the following format:
{
"message": "Request failed for ___ returned code___. Truncated server response: {___SERVER_RESPONSE_OBJECT___} (use muteHttpExceptions option to examine full response)",
"name": "Exception",
"fileName": "___FILE_NAME___",
"lineNumber": ___LINE_NUMBER___,
"stack": "___STACK_DETAILS___"
}
If you for some reason prefer not using muteHttpExceptions
, you could catch the exception e
, look at e.message
, substring the text between "Truncated server response: " and " (use muteHttpExceptions option to examine full response)", JSON.parse() it, and the returned object would be the error returned from the api call.
I wouldn't suggest it over muteHttpExceptions
, just wanted to show the best way to get the error object this way.
Anyways, try-catch your UrlFetchApp.fetch()
call to make sure you catch the unhandled exceptions, like 404.