Skip to content

Commit 349fbab

Browse files
authored
Merge pull request #2828 from KoenZomers/Issue2818
Added clearer error message when connecting using an expired clientsecret
2 parents fdad851 + 8253439 commit 349fbab

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
4444
- Added `-ApplicationId` as alias for `-ClientId` in `Connect-PnPOnline` and `Request-PnPAccessToken` cmdlets. [#2805](https://github.com/pnp/powershell/pull/2805)
4545
- 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)
4646
- 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)
47+
- Added clearer error message when connecting using an expired client secret and trying to execute a command
4748

4849
### Changed
4950

src/Commands/Base/PnPConnectedCmdlet.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.IO;
23
using System.Linq;
34
using System.Management.Automation;
45

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

73+
case System.Reflection.TargetInvocationException tex:
74+
Exception innermostException = tex;
75+
while (innermostException.InnerException != null) innermostException = innermostException.InnerException;
76+
77+
if (innermostException is System.Net.WebException wex)
78+
{
79+
using(var streamReader = new StreamReader (wex.Response.GetResponseStream()))
80+
{
81+
errorMessage = $"{wex.Status}: {wex.Message} Response received: {streamReader.ReadToEnd()}";
82+
}
83+
}
84+
else
85+
{
86+
errorMessage = innermostException.Message;
87+
}
88+
break;
89+
7290
default:
7391
errorMessage = ex.Message;
7492
break;

0 commit comments

Comments
 (0)