spacebarchat / server

Spacebar server - A reimplementation of the Discord.com backend, built with Typescript and love
https://spacebar.chat
GNU Affero General Public License v3.0
1.42k stars 243 forks source link

Empty string on no username #1040

Open bitfl0wer opened 1 year ago

bitfl0wer commented 1 year ago

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):

Env and Software info

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

MaddyUnderStars commented 1 year ago

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

pawanmkr commented 1 year ago

what should be the error message if not this?

bitfl0wer commented 1 year ago

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