Skip to content

Commit

Permalink
Merge pull request #2828 from KoenZomers/Issue2818
Browse files Browse the repository at this point in the history
Added clearer error message when connecting using an expired clientsecret
  • Loading branch information
gautamdsheth authored Feb 17, 2023
2 parents fdad851 + 8253439 commit 349fbab
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Added `-ApplicationId` as alias for `-ClientId` in `Connect-PnPOnline` and `Request-PnPAccessToken` cmdlets. [#2805](https://github.com/pnp/powershell/pull/2805)
- Added `-Connection` option to `Connect-PnPOnline` which allows of reusing an authenticated connection to connect to a different site [#2821](https://github.com/pnp/powershell/pull/2821)
- Added `-UserAssignedManagedIdentityAzureResourceId` and `-UserAssignedManagedIdentityClientId` as alternatives to `-UserAssignedManagedIdentityObjectId` for `Connect-PnPOnline -ManagedIdentity` to provide an user managed identity to authenticate with. [#2813](https://github.com/pnp/powershell/pull/2813)
- Added clearer error message when connecting using an expired client secret and trying to execute a command

### Changed

Expand Down
18 changes: 18 additions & 0 deletions src/Commands/Base/PnPConnectedCmdlet.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.IO;
using System.Linq;
using System.Management.Automation;

Expand Down Expand Up @@ -69,6 +70,23 @@ protected override void ProcessRecord()
errorMessage = (rex.Error as PnP.Core.SharePointRestError).Message;
break;

case System.Reflection.TargetInvocationException tex:
Exception innermostException = tex;
while (innermostException.InnerException != null) innermostException = innermostException.InnerException;

if (innermostException is System.Net.WebException wex)
{
using(var streamReader = new StreamReader (wex.Response.GetResponseStream()))
{
errorMessage = $"{wex.Status}: {wex.Message} Response received: {streamReader.ReadToEnd()}";
}
}
else
{
errorMessage = innermostException.Message;
}
break;

default:
errorMessage = ex.Message;
break;
Expand Down

0 comments on commit 349fbab

Please sign in to comment.