mirror of
https://github.com/openziti/zrok.git
synced 2025-01-03 04:29:19 +01:00
account creation error handling
This commit is contained in:
parent
1d0218ad91
commit
efdf5b5293
@ -49,6 +49,6 @@ var createAccountCmd = &cobra.Command{
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
logrus.Infof("api token = '%v'", resp.Payload.APIToken)
|
logrus.Infof("api token: %v", resp.Payload.APIToken)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -56,6 +56,7 @@ func createAccountHandler(params identity.CreateAccountParams) middleware.Respon
|
|||||||
|
|
||||||
token, err := generateApiToken()
|
token, err := generateApiToken()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logrus.Errorf("error generating api token: %v", err)
|
||||||
return middleware.Error(500, err.Error())
|
return middleware.Error(500, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,12 +67,14 @@ func createAccountHandler(params identity.CreateAccountParams) middleware.Respon
|
|||||||
}
|
}
|
||||||
tx, err := str.Begin()
|
tx, err := str.Begin()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logrus.Errorf("error starting transaction: %v", err)
|
||||||
return middleware.Error(500, err.Error())
|
return middleware.Error(500, err.Error())
|
||||||
}
|
}
|
||||||
id, err := str.CreateAccount(a, tx)
|
id, err := str.CreateAccount(a, tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logrus.Errorf("error creating account: %v", err)
|
||||||
_ = tx.Rollback()
|
_ = tx.Rollback()
|
||||||
return middleware.Error(500, err.Error())
|
return middleware.Error(400, err.Error())
|
||||||
}
|
}
|
||||||
if err := tx.Commit(); err != nil {
|
if err := tx.Commit(); err != nil {
|
||||||
logrus.Errorf("error comitting: %v", err)
|
logrus.Errorf("error comitting: %v", err)
|
||||||
|
@ -29,6 +29,18 @@ func (o *CreateAccountReader) ReadResponse(response runtime.ClientResponse, cons
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return result, nil
|
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:
|
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())
|
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
|
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
|
||||||
|
}
|
||||||
|
@ -55,6 +55,12 @@ func init() {
|
|||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/accountResponse"
|
"$ref": "#/definitions/accountResponse"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"400": {
|
||||||
|
"description": "account not created (already exists)"
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "internal server error"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -144,6 +150,12 @@ func init() {
|
|||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/accountResponse"
|
"$ref": "#/definitions/accountResponse"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"400": {
|
||||||
|
"description": "account not created (already exists)"
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "internal server error"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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)
|
||||||
|
}
|
||||||
|
@ -19,6 +19,10 @@ paths:
|
|||||||
description: account created
|
description: account created
|
||||||
schema:
|
schema:
|
||||||
$ref: "#/definitions/accountResponse"
|
$ref: "#/definitions/accountResponse"
|
||||||
|
400:
|
||||||
|
description: account not created (already exists)
|
||||||
|
500:
|
||||||
|
description: internal server error
|
||||||
/version:
|
/version:
|
||||||
get:
|
get:
|
||||||
tags:
|
tags:
|
||||||
|
Loading…
Reference in New Issue
Block a user