Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Validation error messages - Error responses pattern #941

Merged
merged 5 commits into from
Mar 1, 2021

Conversation

cpgo
Copy link
Contributor

@cpgo cpgo commented Feb 26, 2021

Issue Description

See #232

The main goal is to implement the same error format for all our services. This PR implements the error format on validation errors returned by the butler api

Solution

  • Replaced the validations with class-validator package for schema validations with the joi package.
  • Kept the payload format and DTO objects so we dont break anything for now.

Results

The error response now has a bit more information about the error, the main benefit will be on the consumer side when all apis of all services implement this format.

Old error response:

Payload:

{
  "error": "Bad Request",
  "message": [
    "deploymentId should not be empty",
    "deploymentId must be an UUID",
    "authorId should not be empty",
    "authorId must be an UUID",
    "callbackUrl should not be empty",
    "callbackUrl must be a string",
    "cdConfigurationId should not be empty",
    "cdConfigurationId must be an UUID",
    "circle should not be empty",
    "defaultCircle must be a boolean value",
    "modules should not be empty"
  ],
  "statusCode": 400
}

New error response

Payload:

{
  "errors": [
    {
      "status": 400,
      "detail": "'deploymentId' is required",
      "source": {
        "pointer": "deploymentId"
      },
      "meta": {
        "component": "butler",
        "timestamp": 15273840868
      }
    },
    {
      "status": 400,
      "detail": "'defaultCircle' is required",
      "source": {
        "pointer": "defaultCircle"
      },
      "meta": {
        "component": "butler",
        "timestamp": 15273840868
      }
    },
    {
      "status": 400,
      "detail": "'modules' is required",
      "source": {
        "pointer": "modules"
      },
      "meta": {
        "component": "butler",
        "timestamp": 15273840868
      }
    },
    {
      "status": 400,
      "detail": "'authorId' is required",
      "source": {
        "pointer": "authorId"
      },
      "meta": {
        "component": "butler",
        "timestamp": 15273840868
      }
    },
    {
      "status": 400,
      "detail": "'cdConfigurationId' is required",
      "source": {
        "pointer": "cdConfigurationId"
      },
      "meta": {
        "component": "butler",
        "timestamp": 15273840868
      }
    },
    {
      "status": 400,
      "detail": "'callbackUrl' is required",
      "source": {
        "pointer": "callbackUrl"
      },
      "meta": {
        "component": "butler",
        "timestamp": 15273840868
      }
    }
  ]
}

Signed-off-by: Cassio Godinho <cassiopgodinho@gmail.com>
Signed-off-by: Cassio Godinho <cassiopgodinho@gmail.com>
Signed-off-by: Cassio Godinho <cassiopgodinho@gmail.com>
Signed-off-by: Cassio Godinho <cassiopgodinho@gmail.com>
Signed-off-by: Cassio Godinho <cassiopgodinho@gmail.com>
@boring-cyborg boring-cyborg bot added the butler Improvements/additions/fixes for butler module. label Feb 26, 2021
Copy link
Contributor

@thallesfreitaszup thallesfreitaszup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should update on moove too, to receive this new error response pattern

@cpgo
Copy link
Contributor Author

cpgo commented Mar 1, 2021

we should update on moove too, to receive this new error response pattern

Yes, this is planned when we finish all integration with moove.
@lucasbfernandes is working on Moove and there will be another PR changing the deployment payload of butler api, but I think we dont need to block this PR waiting for those changes.

@cpgo cpgo merged commit f31597f into butler-operator Mar 1, 2021
@cpgo cpgo deleted the validation-error-messages branch March 1, 2021 20:09
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
butler Improvements/additions/fixes for butler module.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants