{"record":{"id":"d89926c9d4d30717","repo":"nopSolutions/nopCommerce","slug":"failed-to-delete-customer","errorCode":null,"errorMessage":"Failed to delete customer","messagePattern":"Failed to delete customer","errorType":"exception","errorClass":"NopException","httpStatus":null,"severity":"error","filePath":"src/Plugins/Nop.Plugin.Tax.Avalara/Services/AvalaraTaxManager.cs","lineNumber":1634,"sourceCode":"    }\n\n    /// <summary>\n    /// Delete a customer with the passed identifier\n    /// </summary>\n    /// <param name=\"customerId\">Customer id</param>\n    /// <returns>\n    /// A task that represents the asynchronous operation\n    /// The task result contains the customer details\n    /// </returns>\n    public async Task<CustomerModel> DeleteCustomerAsync(int customerId)\n    {\n        return (await HandleFunctionAsync(async () =>\n        {\n            if (_avalaraTaxSettings.CompanyId is null)\n                throw new NopException(\"Company not selected\");\n\n            return await ServiceClient.DeleteCustomerAsync(_avalaraTaxSettings.CompanyId.Value, customerId.ToString())\n                ?? throw new NopException(\"Failed to delete customer\");\n        })).Result;\n    }\n\n    /// <summary>\n    /// Get valid certificates linked to a customer in a particular country and region\n    /// </summary>\n    /// <param name=\"customer\">Customer</param>\n    /// <param name=\"storeId\">Current store id</param>\n    /// <returns>\n    /// A task that represents the asynchronous operation\n    /// The task result contains the list of certificates\n    /// </returns>\n    public async Task<CertificateModel> GetValidCertificatesAsync(Customer customer, int storeId)\n    {\n        return (await HandleFunctionAsync(async () =>\n        {\n            if (_avalaraTaxSettings.CompanyId is null)\n                throw new NopException(\"Company not selected\");","sourceCodeStart":1616,"sourceCodeEnd":1652,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Plugins/Nop.Plugin.Tax.Avalara/Services/AvalaraTaxManager.cs#L1616-L1652","documentation":"Thrown when ServiceClient.DeleteCustomerAsync(companyId, customerCode) returns null. Avalara's SDK returns a null result (rather than throwing) when the customer could not be deleted, so the ?? coalesce converts that silent failure into a NopException wrapped by HandleFunctionAsync.","triggerScenarios":"Calling DeleteCustomerAsync for a customerId that does not exist in Avalara CertCapture under the given company; the customer is locked by another transaction; the Avalara service returns an empty/null payload after a 4xx/5xx.","commonSituations":"Local nopCommerce customer IDs that were never synced to Avalara; stale customerId passed after the customer was already deleted; transient Avalara API outage returning a non-200 with a null deserialized body.","solutions":["Verify the customerId/customerCode actually exists in Avalara CertCapture for the configured company before attempting deletion.","Inspect the log entry written by HandleFunctionAsync for the underlying Avalara SDK error or HTTP status.","Treat a 'customer not found' case as success (idempotent delete) instead of throwing — verify against ListCustomersAsync first if needed."],"exampleFix":"// before\nreturn await ServiceClient.DeleteCustomerAsync(_avalaraTaxSettings.CompanyId.Value, customerId.ToString())\n    ?? throw new NopException(\"Failed to delete customer\");\n\n// after — distinguish missing customer from a real failure\nvar deleted = await ServiceClient.DeleteCustomerAsync(_avalaraTaxSettings.CompanyId.Value, customerId.ToString());\nif (deleted is null)\n{\n    var existing = await ServiceClient.GetCustomerAsync(_avalaraTaxSettings.CompanyId.Value, customerId.ToString());\n    if (existing is null) return null; // already gone — idempotent\n    throw new NopException(\"Failed to delete customer\");\n}\nreturn deleted;","handlingStrategy":"try-catch","validationCode":"var existing = await ServiceClient.GetCustomerAsync(_avalaraTaxSettings.CompanyId.Value, customerId.ToString());\nif (existing is null) { /* already absent — treat as deleted */ return; }","typeGuard":null,"tryCatchPattern":"try { await _avalaraTaxManager.DeleteCustomerAsync(id); }\ncatch (NopException ex) when (ex.Message.Contains(\"Failed to delete customer\"))\n{ _logger.LogError(ex, \"Avalara delete failed for {Id}\", id); throw; }","preventionTips":["Sync/link customers to Avalara before issuing delete operations.","Make deletes idempotent by checking existence first and treating 'not found' as success.","Log the underlying Avalara SDK response inside HandleFunctionAsync to capture HTTP status."],"tags":["avalara","certcapture","null-response","nopcommerce"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}