server icon indicating copy to clipboard operation
server copied to clipboard

Empty string on no username

Open bitfl0wer opened this issue 2 years ago • 3 comments
trafficstars

Describe the bug When I send a request to /api/auth/register with the following json body:

{
  "username": "Hi",
  "consent": false
}

I get this error:

{
  "code": 50035,
  "message": "Invalid Form Body",
  "errors": {
    "consent": {
      "_errors": [
        {
          "message": "You must agree to the Terms of Service and Privacy Policy.",
          "code": "CONSENT_REQUIRED"
        }
      ]
    }
  }
}

So far, so good. However, if I don't supply a username, like this:

{
  "consent": false
}

, the response looks like this:

{
  "code": 50035,
  "message": "Invalid Form Body",
  "errors": {
    "": {
      "_errors": [
        {
          "message": "must have required property 'username'",
          "code": "required"
        }
      ]
    }
  }
}

The field under "errors" is just an empty string. Is this supposed to be like that?

System Information (please complete the following information):

  • OS: Arch btw
  • Node Version: Node v19.9.0
  • Python 3 Version: Python 3.10.10

Env and Software info

  • Branch (if release is not applicable): main
  • Commit Hash: 174d34c376a6a94c88b163cf46f76f2b6e52e633
  • Database: SQLite
  • Reverse Proxy: n.a.
  • Thread Count:

Additional context i hate json i hate json i hate json i hate json i hate json i hate json

bitfl0wer avatar Apr 22 '23 17:04 bitfl0wer

for later, the bug is here: https://github.com/spacebarchat/server/blob/1d19db52ebe86d3fcbb8f3837407100e5c15ad73/src/api/util/handlers/route.ts#L100-L116

MaddyUnderStars avatar Apr 23 '23 07:04 MaddyUnderStars

what should be the error message if not this?

pawanmkr avatar May 05 '23 15:05 pawanmkr

Probably username, to indicate that it is an error with the username. An empty string just doesn't say much about the error

bitfl0wer avatar May 05 '23 19:05 bitfl0wer