Skip to content
This repository was archived by the owner on Sep 2, 2020. It is now read-only.
This repository was archived by the owner on Sep 2, 2020. It is now read-only.

Badge field 'type' is not 'required', but the request fails if it's not supplied #90

Closed

Description

@tgs

I get a 500 error when POSTing a new badge if I don't supply the 'type' field in the request body. The error message is ER_BAD_NULL_ERROR: Column 'type' cannot be null. I assume there's a list of 'required fields' somewhere - if 'type' is required, it should be added to that list; if not, the schema should be changed so that badges.type is allowed to be null.

Activity

  1. SueSmith commented on May 28, 2014

    @SueSmith
    Contributor

    I'm working through the docs at the moment here https://github.com/mozilla/badgekit-api/tree/doc-updates/docs

    Funnily enough I came across this one myself earlier.. Not sure if it's meant to be required or not but will need to check on it and various other things I'm not sure about 😉

    Hoping to get through all of the endpoints within the next few days so the docs on the master branch should be updated and a lot more detailed then..

  2. tgs commented on May 28, 2014

    @tgs
    ContributorAuthor

    Thanks! To clarify, it should be listed both in the documentation, and in the error-checking routines in the code. For instance, if you leave out 'earnerDescription' and 'consumerDescription', the server gives you back a 'ValidationError' code and a 'details' list that tells you which fields were missing.

  3. SueSmith commented on May 28, 2014

    @SueSmith
    Contributor

    Ah cool, thanks for clarifying.

  4. added a commit that references this issue on May 28, 2014
  5. cmcavoy commented on Jun 6, 2014

    @cmcavoy
    Contributor

    Docs updated in #91.

  6. tgs commented on Jun 9, 2014

    @tgs
    ContributorAuthor

    Thanks for updating the docs! Unfortunately, this is still only half-fixed.

    When I try to create a badge that's missing another field, like consumerDescription, I get back an HTTP 400, Bad Request, and a nice JSON error that looks like this:

    {
       "details" : [
          {
             "value" : "",
             "field" : "consumerDescription"
          }
       ],
       "message" : "Could not validate required fields",
       "code" : "ValidationError"
    }
    

    As an author of a client library, I can format that into an Exception that lists the missing fields, and the user of my client can presumably do something intelligent with this, like show an error message on the relevant form field.

    By contrast, when I try to create a badge that's missing the type field, I get an HTTP 500, and this response:

    {"message": "ER_BAD_NULL_ERROR: Column 'type' cannot be null"}
    

    This indicates that the missing field is not being caught by the validation layer, but makes it all the way to the database before being noticed. So the JS representation of what fields are required doesn't match the database. I can't make as useful an Exception from this, and the 500 error code means "something went wrong with the server", so it's not as obvious that the request was the problem.

    Honestly, this is not a big problem for me, because I don't expect to be making badges in my application. So don't prioritize it on my behalf, but it might still be a good opportunity to make sure the validation routines match the database's expectations.

  7. cmcavoy commented on Jun 10, 2014

    @cmcavoy
    Contributor

    Thanks @tgs this also points out that we need to standardize error
    responses.

    On Mon, Jun 9, 2014 at 12:01 PM, Thomas Smith notifications@github.com
    wrote:

    Thanks for updating the docs! Unfortunately, this is still only half-fixed.

    When I try to create a badge that's missing another field, like
    consumerDescription, I get back an HTTP 400, Bad Request, and a nice JSON
    error that looks like this:

    {
    "details" : [
    {
    "value" : "",
    "field" : "consumerDescription"
    }
    ],
    "message" : "Could not validate required fields",
    "code" : "ValidationError"
    }

    As an author of a client library, I can format that into an Exception that
    lists the missing fields, and the user of my client can presumably do
    something intelligent with this, like show an error message on the relevant
    form field.

    By contrast, when I try to create a badge that's missing the type field,
    I get an HTTP 500, and this response:

    {"message": "ER_BAD_NULL_ERROR: Column 'type' cannot be null"}

    This indicates that the missing field is not being caught by the
    validation layer, but makes it all the way to the database before being
    noticed. So the JS representation of what fields are required doesn't match
    the database. I can't make as useful an Exception from this, and the 500
    error code means "something went wrong with the server", so it's not as
    obvious that the request was the problem.

    Honestly, this is not a big problem for me, because I don't expect to be
    making badges in my application. So don't prioritize it on my behalf, but
    it might still be a good opportunity to make sure the validation routines
    match the database's expectations.

    —
    Reply to this email directly or view it on GitHub
    #90 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions