# Passing an api\_username for a user that does not exist returns a 500 with no useful context

**URL:** <https://meta.discourse.org/t/passing-an-api-username-for-a-user-that-does-not-exist-returns-a-500-with-no-useful-context/46407>\
**Category:** Development\
**Created:** [2016 年6 月 24 日 16:06 UTC](https://meta.discourse.org/t/passing-an-api-username-for-a-user-that-does-not-exist-returns-a-500-with-no-useful-context/46407 "2016-06-24T16:06:12Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

作者： ![cappslock](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cappslock/32/120789_2.png) [@cappslock](https://meta.discourse.org/u/cappslock)\
发布日期： [2016 年6 月 24 日 16:06 UTC](https://meta.discourse.org/t/passing-an-api-username-for-a-user-that-does-not-exist-returns-a-500-with-no-useful-context/46407/1 "2016-06-24T16:06:12Z")

</div>

On the beta branch, when attempting to create a POST on behalf of a user, I use the API and provide the username as the `api_username`. Because of the way I’m managing users, the user may not exist in Discourse at this time and I’d like to be able to respond to that exception by creating the user. It would be useful if the error had enough context to determine that this case occurred, but instead, it’s raising a Discourse::InvalidAccess and the server is returning a 500.

Strack trace:

```plaintext
lib/auth/default_current_user_provider.rb:57:in `current_user'
lib/current_user.rb:30:in `current_user'
app/helpers/application_helper.rb:59:in `html_classes'
app/views/layouts/application.html.erb:2:in `_app_views_layouts_application_html_erb__210758119167932006_91259420'
app/controllers/application_controller.rb:496:in `build_not_found_page'
app/controllers/application_controller.rb:134:in `rescue_discourse_actions'
app/controllers/application_controller.rb:117:in `block in <class:ApplicationController>'
config/initializers/100-quiet_logger.rb:13:in `call_with_quiet_assets'
config/initializers/100-silence_logger.rb:26:in `call'
lib/middleware/missing_avatars.rb:21:in `call'
lib/middleware/turbo_dev.rb:33:in `call'

```

I can work around this, but it would be nice if the server responded with something in the 4xx range and enough information to determine the cause of the issue.

---

_[View the full topic](https://meta.discourse.org/t/passing-an-api-username-for-a-user-that-does-not-exist-returns-a-500-with-no-useful-context/46407)._
