-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
80 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Newtonsoft.Json; | ||
using Nuke.Common; | ||
|
||
namespace Cloud.Models | ||
{ | ||
public class VirtoCloudError | ||
{ | ||
public string Message { get; set; } | ||
public List<string> Errors { get; set; } | ||
|
||
public string GetErrorMessage() | ||
{ | ||
var message = Message; | ||
if (Errors?.Count > 0) | ||
{ | ||
message += Environment.NewLine + string.Join(Environment.NewLine, Errors); | ||
} | ||
|
||
return message; | ||
} | ||
|
||
public static VirtoCloudError FromStringResponse(string response) | ||
{ | ||
try | ||
{ | ||
var cloudError = JsonConvert.DeserializeObject<VirtoCloudError>(response); | ||
var message = cloudError?.Message ?? response; | ||
var errors = cloudError?.Errors ?? new List<string>(); | ||
return new VirtoCloudError { | ||
Message = message, | ||
Errors = errors | ||
}; | ||
} | ||
catch (JsonReaderException) | ||
{ | ||
return new VirtoCloudError | ||
{ | ||
Message = response | ||
}; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters