dionysia-dev / dionysia

A streaming platform based on open source software
Apache License 2.0
116 stars 7 forks source link

change handleValidatorError to return code and error #1

Closed 1garo closed 3 months ago

1garo commented 3 months ago

Maybe would be more clear when looking at the controller, when responding from inside the function you would need to go to the function and see how it handles it.

func handleValidationError(err error) (int, *ErrorResponse) {
        // ...
    return http.StatusBadRequest, &ErrorResponse{
        Error: Error{
            Message: "Invalid request parameters",
            Details: details,
        },
    }

}

and then:

func (c *InputController) CreateInput(ctx *gin.Context) {
    var inputData model.Input
    if err := ctx.BindJSON(&inputData); err != nil {
        statusCode, errMsg := handleValidationError(err)
        ctx.JSON(statusCode, errMsg)

        return
    }
        // ...
mauricioabreu commented 3 months ago

Hello @1garo thank you for contributing to the project.

I agree with your statement. Want to contribute to the project? If positive, I will wait for your pull request, otherwise tell me so I can fix it ASAP.

1garo commented 3 months ago

I will contribute! Thank you!