account creation error handling

This commit is contained in:
Michael Quigley 2022-07-25 16:23:55 -04:00
parent 1d0218ad91
commit efdf5b5293
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
6 changed files with 123 additions and 2 deletions

View File

@ -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)
},
}

View File

@ -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)

View File

@ -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
}

View File

@ -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"
}
}
}

View File

@ -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)
}

View File

@ -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: