-
Notifications
You must be signed in to change notification settings - Fork 10
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
Add ATError Object Generator #112
Conversation
the aim of #111 was more to have a strongly typed reference such that I can respond with these from an api controller as a pds would. [HttpPost("com.atproto.server.createAccount")]
public async Task<IActionResult> CreateAccount([FromBody] CreateAccountInput request)
{
try
{
var config = await _configRepository.GetConfigAsync();
// directs user back to 'invite code' page in appview
if (string.IsNullOrWhiteSpace(request.InviteCode))
{
// alternatively something akin to return ATErrorResponse(new InvalidInviteCodeError(StatusCode.BadRequest, "missing or invalid invite code"));
return ATErrorResponse(Com.Atproto.Server.CreateAccount.Errors.InvalidInviteCode, "missing or invalid invite code");
}
...
public static IActionResult ATErrorResponse<T>(T enumError, string message) where T : Enum
{
return new ErrorResponseResult<T>(enumError, message, HttpStatusCode.BadRequest);
}
public class ErrorResponseResult<T> : ObjectResult where T : Enum
{
public ErrorResponseResult(T enumError, string message, HttpStatusCode statusCode) : base(new { error = enumError.ToString(), message = message })
{
StatusCode = (int)statusCode;
}
} Personally my thoughts on the approach you have taken would be that you should still be able to construct an error type with the detail.Error field pre-populated new InvalidInviteCodeError(statusCode, message)
namespace FishyFlip.Lexicon
{
/// <summary>
/// FishyFlip ATError for InvalidInviteCode.
/// </summary>
public class InvalidInviteCodeError : FishyFlip.Models.ATError
{
public const string ErrorType = "InvalidInviteCode";
public InvalidInviteCodeError(int statusCode, ErrorDetail detail) : base(statusCode, detail)
{
}
public InvalidInviteCodeError(int statusCode, string message) : base(statusCode, new ErrorDetail(ErrorType, message))
{
}
}
} |
I also think it would be nice to preserve the namespace and descriptions associated with the error responses but given that multiple routes can have the same error type it would cause issues in ATErrorGenerator.g.cs in it's current state since there would be multiple classes for a given errorType. Perhaps they could just be included as part of the summary xmldoc |
|
The description values do have use for the Endpoint classes when stating the list of errors and what could be expected, so they could be added to the top constructor of the given I see your point for using For example, in your use-case of the Invite Code. For a front-end client, you would be checking that with client-side validation first most likely to prevent that request from hitting your server. Your backend code could also validate it before calling ATProtocol, but you would probably want to handle that error yourself to make it clear that something went wrong in your application to get to that state, rather than return an object from this library. Or you could not validate that value in the backend, let it get processed by ATProtocol, which would return the error object, that you then pass back to your client application to handle. |
* Add missing parameters to getAuthorFeed * Don't set ATError object when logging * Add AspectRatio to ImageView * Start sourcegen * Update * Update Tools * Update * Remove usings, since it's in global * Try again * update * Update * Update * Update * Update * Update * Update * Almost... * Update * Update * Update logging-in.md * Add codeflow to readme * Update... * Expose the Cursor on the NotificationCollection * Almost... maybe... * Firehose * Update * The big one * Update * Update... * Fix Readme * Start refactoring... * More types * More cleanup * More modding... * More types... * Closer... * Nearly... * Fun! * First run! * Tests and More * Add Tests for Endpoints * Add class entries * Trying to generate helpers... * More generated Parameters * And helper methods! * Update Generated Types with less aggressive Null values Also fix JSON ATObject type to allow fallback * Update Docs, bump ATProto again... * Revert... * Revert... * Revert... * Add parameter constructors... * Update docs * More docs * Update docs * Adjust tests (???) * Remove deprecated classes and methods * Remove FishyFlipDX, Replace FishyFlip with Source Gen Bits (#104) +semver: breaking * Add docs, bump to net9.0 (#105) * Add docs, bump to net9.0 * Bump to net9 * Fix ImportRepo, add OpenGraphParser (#106) * Fix ImportRepo * Add OpenGraphParser * Cleanup + Fix WASM support (#108) * Order by classname * Update * small cleanup * Update * Use SupportsAutomaticDecompression for setting AutomaticDecompression, add WASM site back * Add WhiteWind Generator, add GetRecord (#110) * Add ATError Object Generator (#112) * Add Error Generator * Add Possible Errors * Warning cleanup * Add ToString override for ATError (#113) * Fix GetBlob to return byte[] (#114) * Resolve Repo DIDs and Handles independently (#115) * Start refactoring URL * Update * Fix tests * Fix Facet Parsing (#116) * Fix Facet Parsing * Remove DistinctBy * Reintroduce bskycli (#117) * Add bskycli * Image Aspect Ratio * Update * Update * Update readme * Update * Fix Windows script * Bump ATProtocol, Bind ATFile Lexicon support (#118) * Bump atprotocol * Add ATFile support * Add build_binding script (#119) * Update PasswordAuth with AuthenticateWithPasswordResultAsync (#120) * Update PasswordAuth with AuthenticateWithPasswordResultAsync * Really??? * Use public.api.bsky.app for unauthed sessions by default (#121) * Add 2FA Auth Token support for Password Auth (#122) * Bump dependencies (#123) * Add Post helper for PostView (#124) * Bump dependencies (#125) * Resolve users PDS before authentication (#126) * Add Pastesphere support (#127) * Add AniBlue support (#128) * Bump Bindings (#129) * Add community lexicons (#130) * Add DidDoc helpers (#131) * patch: Special case booleans (#132) * Bump bindings (#133) * Override ATUri/ATIdentifier Equals for proper checking (#134) * Bump bindings * Override Equals * Add support for setting Labels / Fixes Chat (#135) * Update SourceGen for Labels * Update for labels * Fix chat too --------- Co-authored-by: Thomas May <[email protected]> Co-authored-by: Kevin Gosse <[email protected]> Co-authored-by: Matt Brailsford <[email protected]>
Inspired by @PassiveModding's PR for #111, this generates
ATError
objects based on theerror
object within the lexicon for a given endpoint. This is just hacked together to expose the idea of it (It could be expanded to use details if available, or be included in the constructor documentation as possible error types) but it should now make it possible to switch inside of theerror
flow for a given error, rather than inspecting it yourself.