diff --git a/cmd/zrok/create.go b/cmd/zrok/create.go index 1163d4f7..e7df9d0a 100644 --- a/cmd/zrok/create.go +++ b/cmd/zrok/create.go @@ -49,6 +49,6 @@ var createAccountCmd = &cobra.Command{ panic(err) } - logrus.Infof("api token = '%v'", resp.Payload.APIToken) + logrus.Infof("api token: %v", resp.Payload.APIToken) }, } diff --git a/controller/controller.go b/controller/controller.go index 46a4ca6d..45eaa061 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -56,6 +56,7 @@ func createAccountHandler(params identity.CreateAccountParams) middleware.Respon token, err := generateApiToken() if err != nil { + logrus.Errorf("error generating api token: %v", err) return middleware.Error(500, err.Error()) } @@ -66,12 +67,14 @@ func createAccountHandler(params identity.CreateAccountParams) middleware.Respon } tx, err := str.Begin() if err != nil { + logrus.Errorf("error starting transaction: %v", err) return middleware.Error(500, err.Error()) } id, err := str.CreateAccount(a, tx) if err != nil { + logrus.Errorf("error creating account: %v", err) _ = tx.Rollback() - return middleware.Error(500, err.Error()) + return middleware.Error(400, err.Error()) } if err := tx.Commit(); err != nil { logrus.Errorf("error comitting: %v", err) diff --git a/rest_zrok_client/identity/create_account_responses.go b/rest_zrok_client/identity/create_account_responses.go index 3c9f1915..04358202 100644 --- a/rest_zrok_client/identity/create_account_responses.go +++ b/rest_zrok_client/identity/create_account_responses.go @@ -29,6 +29,18 @@ func (o *CreateAccountReader) ReadResponse(response runtime.ClientResponse, cons return nil, err } return result, nil + case 400: + result := NewCreateAccountBadRequest() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + case 500: + result := NewCreateAccountInternalServerError() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result default: return nil, runtime.NewAPIError("response status code does not match any response statuses defined for this endpoint in the swagger spec", response, response.Code()) } @@ -65,3 +77,45 @@ func (o *CreateAccountCreated) readResponse(response runtime.ClientResponse, con return nil } + +// NewCreateAccountBadRequest creates a CreateAccountBadRequest with default headers values +func NewCreateAccountBadRequest() *CreateAccountBadRequest { + return &CreateAccountBadRequest{} +} + +/* CreateAccountBadRequest describes a response with status code 400, with default header values. + +account not created (already exists) +*/ +type CreateAccountBadRequest struct { +} + +func (o *CreateAccountBadRequest) Error() string { + return fmt.Sprintf("[POST /account][%d] createAccountBadRequest ", 400) +} + +func (o *CreateAccountBadRequest) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + return nil +} + +// NewCreateAccountInternalServerError creates a CreateAccountInternalServerError with default headers values +func NewCreateAccountInternalServerError() *CreateAccountInternalServerError { + return &CreateAccountInternalServerError{} +} + +/* CreateAccountInternalServerError describes a response with status code 500, with default header values. + +internal server error +*/ +type CreateAccountInternalServerError struct { +} + +func (o *CreateAccountInternalServerError) Error() string { + return fmt.Sprintf("[POST /account][%d] createAccountInternalServerError ", 500) +} + +func (o *CreateAccountInternalServerError) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + return nil +} diff --git a/rest_zrok_server/embedded_spec.go b/rest_zrok_server/embedded_spec.go index bcc7cf0d..42ef2633 100644 --- a/rest_zrok_server/embedded_spec.go +++ b/rest_zrok_server/embedded_spec.go @@ -55,6 +55,12 @@ func init() { "schema": { "$ref": "#/definitions/accountResponse" } + }, + "400": { + "description": "account not created (already exists)" + }, + "500": { + "description": "internal server error" } } } @@ -144,6 +150,12 @@ func init() { "schema": { "$ref": "#/definitions/accountResponse" } + }, + "400": { + "description": "account not created (already exists)" + }, + "500": { + "description": "internal server error" } } } diff --git a/rest_zrok_server/operations/identity/create_account_responses.go b/rest_zrok_server/operations/identity/create_account_responses.go index 20a32b9c..8588d37d 100644 --- a/rest_zrok_server/operations/identity/create_account_responses.go +++ b/rest_zrok_server/operations/identity/create_account_responses.go @@ -56,3 +56,51 @@ func (o *CreateAccountCreated) WriteResponse(rw http.ResponseWriter, producer ru } } } + +// CreateAccountBadRequestCode is the HTTP code returned for type CreateAccountBadRequest +const CreateAccountBadRequestCode int = 400 + +/*CreateAccountBadRequest account not created (already exists) + +swagger:response createAccountBadRequest +*/ +type CreateAccountBadRequest struct { +} + +// NewCreateAccountBadRequest creates CreateAccountBadRequest with default headers values +func NewCreateAccountBadRequest() *CreateAccountBadRequest { + + return &CreateAccountBadRequest{} +} + +// WriteResponse to the client +func (o *CreateAccountBadRequest) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.Header().Del(runtime.HeaderContentType) //Remove Content-Type on empty responses + + rw.WriteHeader(400) +} + +// CreateAccountInternalServerErrorCode is the HTTP code returned for type CreateAccountInternalServerError +const CreateAccountInternalServerErrorCode int = 500 + +/*CreateAccountInternalServerError internal server error + +swagger:response createAccountInternalServerError +*/ +type CreateAccountInternalServerError struct { +} + +// NewCreateAccountInternalServerError creates CreateAccountInternalServerError with default headers values +func NewCreateAccountInternalServerError() *CreateAccountInternalServerError { + + return &CreateAccountInternalServerError{} +} + +// WriteResponse to the client +func (o *CreateAccountInternalServerError) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.Header().Del(runtime.HeaderContentType) //Remove Content-Type on empty responses + + rw.WriteHeader(500) +} diff --git a/specs/zrok.yml b/specs/zrok.yml index a3beebac..c759c199 100644 --- a/specs/zrok.yml +++ b/specs/zrok.yml @@ -19,6 +19,10 @@ paths: description: account created schema: $ref: "#/definitions/accountResponse" + 400: + description: account not created (already exists) + 500: + description: internal server error /version: get: tags: