# Error Handling

## Check Error Code and Message

If `throwExceptionOnError()` is not turned on, then for all requests that are not made successful, `DataService` will store the `error` object.

To retrieve the `error` object, call the `getLastError()` method of the `DataService` object:

    // Make the API call
    $result = $dataService->Add($theTargetObj);
    $error =  $dataService->getLastError();

By default, `$dataService->getLastError()` returns `FALSE` for a successful API call, so you can simply use an `if` statement to check if the last API request was successful:

    // Make the API call
    $result = $dataService->Add($theTargetObj);
    $error =  $dataService->getLastError();
    if($error) {
        ...
    } else {
        ....
    }

If the API request fails, use `getHttpStatusCode()` and `getResponseBody()` to get the status code and response message of the failed request, which provides information to help you identify the cause:

    //Make the API call
    $result = $dataService->Add($theTargetObj);
    $error =  $dataService->getLastError();
    if($error) {
        echo "The Status code is: " . $error->getHttpStatusCode() . "\n";
        echo "The Response message is: " . $error->getResponseBody() . "\n";
    } else {
        ....
    }

## Report an Error to Intuit

Sometimes the error returned by QuickBooks Online may not be clear, and you would like Intuit Support to help identify the cause. If so, use the following code to record the Intuit-tid from the response, and send us this value along with the Request and Response log you recorded, so we can help you diagnose the issue:

    $intuit_tid = $error->getIntuitTid();