upb-uc4 / lagom-core

Repository for the micro service backend using lagom.
Apache License 2.0
6 stars 0 forks source link

Course Validation #277

Closed bastihav closed 4 years ago

bastihav commented 4 years ago

Describe the bug Trying to post a course with no lecturerId will result in a 404 (internal 404 to your user-management)

To Reproduce

{
    "courseType": "",
    "courseId": "",
    "courseName": "",
    "lecturerId": "",
    "ects": 1,
    "maxParticipants": 0,
    "currentParticipants": 0,
    "courseDescription": "",
    "courseLanguage": "",
    "startDate": "2020-06-01",
    "endDate": "2020-08-31"
}

results in

{
    "name": "deserialization exception",
    "detail": "<!DOCTYPE html>\n<html lang=\"en\">\n    <head>\n        <title>Not Found</title>\n        \n<style  type=\"text/css\">\n            html, body, pre {\n                margin: 0;\n                padding: 0;\n                font-family: Monaco, 'Lucida Console', monospace;\n                background: #ECECEC;\n            }\n            h1 {\n                margin: 0;\n                background: #AD632A;\n                padding: 20px 45px;\n                color: #fff;\n                text-shadow: 1px 1px 1px rgba(0,0,0,.3);\n                border-bottom: 1px solid #9F5805;\n                font-size: 28px;\n            }\n            p#detail {\n                margin: 0;\n                padding: 15px 45px;\n                background: #F6A960;\n                border-top: 4px solid #D29052;\n                color: #733512;\n                text-shadow: 1px 1px 1px rgba(255,255,255,.3);\n                font-size: 14px;\n                border-bottom: 1px solid #BA7F5B;\n            }\n        </style>\n    </head>\n    <body>\n        <h1>Not Found</h1>\n\n        <p id=\"detail\">\n            For request 'GET /user-management/users/'\n        </p>\n\n    </body>\n</html>\n"
}

Expected behavior 422 with invalid params :)

Additional context Experimental cluster

david-buderus commented 4 years ago

The problem is here (line 66 and 133 in CourseServiceImpl):

// Check if the lecturer does exist
userService.getUser(courseProposal.lecturerId).handleRequestHeader(addAuthenticationHeader(header)).invoke().recover {
  //If the lecturer does not exist, we throw a validation error, containing that info
  case ex: CustomException if ex.getErrorCode.http == 404 =>
    throw new CustomException(422, DetailedError(ErrorType.Validation, courseProposal.validate :+ SimpleError("lecturerId", "Lecturer does not exist")))

Lagom maps the call intern to the path: /user-management/users/, which does not exists.

But here is an API Problem: Vue wants to have all validation errors at the same time, this includes OwnerMismatch, not exisiting lecturer and so on