-
Notifications
You must be signed in to change notification settings - Fork 313
chore: added Exception as per new Api Standards #814
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+501
−29
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,8 @@ | ||
| { | ||
| "permissions": { | ||
| "allow": [ | ||
| "Bash(dotnet test:*)", | ||
| "Bash(dotnet run:*)" | ||
| ] | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| using System; | ||
| using System; | ||
| using System.Collections.Generic; | ||
|
|
||
| namespace Twilio.Exceptions | ||
|
|
||
This file contains hidden or 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,90 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
|
|
||
| namespace Twilio.Exceptions | ||
| { | ||
| /// <summary> | ||
| /// RFC 9457 compliant API Exception for HTTP APIs | ||
| /// </summary> | ||
| public class ApiStandardException : TwilioException | ||
| { | ||
| /// <summary> | ||
| /// Twilio error code | ||
| /// </summary> | ||
| public int Code { get; } | ||
|
|
||
| /// <summary> | ||
| /// HTTP status code | ||
| /// </summary> | ||
| public int Status { get; } | ||
|
|
||
| /// <summary> | ||
| /// A URI reference identifying the problem type (RFC 9457) | ||
| /// </summary> | ||
| public string Type { get; } | ||
|
|
||
| /// <summary> | ||
| /// A short, human-readable summary of the problem type (RFC 9457) | ||
| /// </summary> | ||
| public string Title { get; } | ||
|
|
||
| /// <summary> | ||
| /// A human-readable explanation specific to this occurrence of the problem (RFC 9457) | ||
| /// </summary> | ||
| public string Detail { get; } | ||
|
|
||
| /// <summary> | ||
| /// A URI reference that identifies the specific occurrence of the problem (RFC 9457) | ||
| /// </summary> | ||
| public string Instance { get; } | ||
|
|
||
| /// <summary> | ||
| /// Validation errors for this occurrence (RFC 9457 extension) | ||
| /// </summary> | ||
| public List<ErrorDetail> Errors { get; } | ||
|
|
||
| /// <summary> | ||
| /// Create an ApiStandardException with message | ||
| /// </summary> | ||
| /// <param name="message">Exception message</param> | ||
| public ApiStandardException(string message) : base(message) { } | ||
|
|
||
| /// <summary> | ||
| /// Create an ApiStandardException from another Exception | ||
| /// </summary> | ||
| /// <param name="message">Exception message</param> | ||
| /// <param name="exception">Exception to copy details from</param> | ||
| public ApiStandardException(string message, Exception exception) : base(message, exception) { } | ||
|
|
||
| /// <summary> | ||
| /// Create an ApiStandardException with RFC 9457 fields | ||
| /// </summary> | ||
| /// <param name="code">Twilio error code</param> | ||
| /// <param name="status">HTTP status code</param> | ||
| /// <param name="type">URI reference identifying the problem type (RFC 9457)</param> | ||
| /// <param name="title">Short summary of the problem type (RFC 9457)</param> | ||
| /// <param name="detail">Human-readable explanation specific to this occurrence (RFC 9457)</param> | ||
| /// <param name="instance">URI identifying this specific occurrence (RFC 9457)</param> | ||
| /// <param name="errors">Validation errors (RFC 9457)</param> | ||
| /// <param name="exception">Original exception</param> | ||
| public ApiStandardException( | ||
| int code, | ||
| int status, | ||
| string type, | ||
| string title, | ||
| string detail, | ||
| string instance, | ||
| List<ErrorDetail> errors, | ||
| Exception exception = null | ||
| ) : base(detail ?? title, exception) | ||
| { | ||
| Code = code; | ||
| Status = status; | ||
| Type = type; | ||
| Title = title; | ||
| Detail = detail; | ||
| Instance = instance; | ||
| Errors = errors; | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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,94 @@ | ||
| using Newtonsoft.Json; | ||
| using System.Collections.Generic; | ||
|
|
||
| namespace Twilio.Exceptions | ||
| { | ||
| /// <summary> | ||
| /// Represents a single validation error detail (RFC 9457) | ||
| /// </summary> | ||
| [JsonObject(MemberSerialization.OptIn)] | ||
| public class ErrorDetail | ||
| { | ||
| /// <summary> | ||
| /// A human-readable explanation of the validation error for this specific field. | ||
| /// </summary> | ||
| [JsonProperty("detail")] | ||
| public string Detail { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// A JSON Pointer (RFC 6901) to the location in the request where the error occurred. | ||
| /// </summary> | ||
| [JsonProperty("pointer")] | ||
| public string Pointer { get; set; } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// RFC 9457 compliant REST API Standard Exception for HTTP APIs | ||
| /// </summary> | ||
| [JsonObject(MemberSerialization.OptIn)] | ||
| public class RestApiStandardException : TwilioException | ||
| { | ||
| /// <summary> | ||
| /// A URI reference identifying the problem type | ||
| /// </summary> | ||
| /// mandatory | ||
| [JsonProperty("type")] | ||
| public string Type { get; private set; } | ||
|
|
||
| /// <summary> | ||
| /// A short, human-readable summary of the problem type | ||
| /// </summary> | ||
| /// mandatory | ||
| [JsonProperty("title")] | ||
| public string Title { get; private set; } | ||
|
|
||
| /// <summary> | ||
| /// The numeric Twilio error code | ||
| /// </summary> | ||
| /// mandatory | ||
| [JsonProperty("code")] | ||
| public int Code { get; private set; } | ||
|
|
||
| /// <summary> | ||
| /// HTTP status code | ||
| /// </summary> | ||
| /// mandatory | ||
| [JsonProperty("status")] | ||
| public int Status { get; private set; } | ||
|
|
||
| /// <summary> | ||
| /// A human-readable explanation specific to this occurrence of the problem | ||
| /// </summary> | ||
| /// optional | ||
| [JsonProperty("detail")] | ||
| public string Detail { get; private set; } | ||
|
|
||
| /// <summary> | ||
| /// A URI reference that identifies the specific occurrence of the problem | ||
| /// </summary> | ||
| /// optional | ||
| [JsonProperty("instance")] | ||
| public string Instance { get; private set; } | ||
|
|
||
| /// <summary> | ||
| /// Validation errors for this occurrence (RFC 9457 extension) | ||
| /// </summary> | ||
| /// optional | ||
| [JsonProperty("errors")] | ||
| public List<ErrorDetail> Errors { get; private set; } | ||
|
|
||
| /// <summary> | ||
| /// Create an empty RestApiStandardException | ||
| /// </summary> | ||
| public RestApiStandardException() { } | ||
|
|
||
| /// <summary> | ||
| /// Create a RestApiStandardException from a JSON payload | ||
| /// </summary> | ||
| /// <param name="json">JSON string to parse</param> | ||
| public static RestApiStandardException FromJson(string json) | ||
| { | ||
| return JsonConvert.DeserializeObject<RestApiStandardException>(json); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this file necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No