Skip to content
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

Introduce generic ASAB error class #546

Closed
wants to merge 3 commits into from
Closed

Conversation

byewokko
Copy link
Collaborator

@byewokko byewokko commented Jan 25, 2024

  • Introduce generic exceptions.ASABError, which follows the structure outlined by Elena.
  • ASABError can be subclassed by different applications for their custom purposes.
  • Introduce asab.web.rest.json.json_error_response function, which generates a HTTP JSON response from ASABError.
  • Add examples.
  • Add documentation.
async def my_handler(request):
  try:
    await create_something()
  except ASABError as e:
    L.log(asab.LOG_NOTICE, e.TechMessage)
    return asab.web.rest.json.json_error_response(request, e, status=409)

async def create_something():
  # Oops...
  raise ASABError(
    error_code=1000,
    tech_message="A record for {!r} already exists".format("stuff"),
    error_i18n_key="Unable to create '{{what}}', because it has already been created by '{{user}}'.",
    error_dict={"what": "stuff", "user": "the queen"},
  )

@byewokko byewokko added the enhancement New feature or request label Jan 25, 2024
@byewokko byewokko self-assigned this Jan 25, 2024
@byewokko
Copy link
Collaborator Author

not desirable, apparently

@byewokko byewokko closed this Jan 26, 2024
@byewokko byewokko deleted the feature/asab-error branch January 26, 2024 09:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant