Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ issues:
- .github
- .make
- dist
- examplecode

# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
max-issues-per-linter: 0
Expand Down
3 changes: 3 additions & 0 deletions actions/v2/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/bitcoin-sv/spv-wallet/api"
"github.com/bitcoin-sv/spv-wallet/config"
"github.com/bitcoin-sv/spv-wallet/engine"
"github.com/bitcoin-sv/spv-wallet/engine/spverrors/examplecode/exampleactions"
"github.com/rs/zerolog"
)

Expand All @@ -21,6 +22,7 @@ type apiV2 struct {
users.APIUsers
operations.APIOperations
transactions.APITransactions
exampleactions.ExampleAPI
}

// NewV2API creates a new server
Expand All @@ -32,5 +34,6 @@ func NewV2API(config *config.AppConfig, engine engine.ClientInterface, logger *z
users.NewAPIUsers(engine, logger),
operations.NewAPIOperations(engine, logger),
transactions.NewAPITransactions(engine, logger),
exampleactions.ExampleAPI{},
}
}
19 changes: 19 additions & 0 deletions api/components/errors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,25 @@ info:

components:
schemas:
ProblemDetails:
type: object
properties:
type:
type: string
description: A URI reference that identifies the problem type
title:
type: string
description: A short, human-readable summary of the problem type
status:
type: integer
description: The HTTP status code
detail:
type: string
description: A human-readable explanation specific to this occurrence of the problem
instance:
type: string
description: A URI reference that identifies the specific occurrence of the problem

Schema:
type: object
properties:
Expand Down
11 changes: 11 additions & 0 deletions api/components/models.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ info:

components:
schemas:
FailingPoint:
type: string
enum:
- "db_connection"
- "db_query"
- "domain_illegal_argument"
- "client_wrong_input"
- "client_auth_wrong"
- "client_auth_missing"
- "internal_during_auth"
- "arc_double_spent_attempt"
SharedConfig:
description: Shared config
type: object
Expand Down
8 changes: 8 additions & 0 deletions api/components/responses.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ info:

components:
responses:
##################
ProblemDetails:
description: Internal server error
content:
application/json:
schema:
$ref: "./errors.yaml#/components/schemas/ProblemDetails"
##################
SharedConfig:
description: Shared config
content:
Expand Down
17 changes: 17 additions & 0 deletions api/endpoints/base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,20 @@ paths:
$ref: "../components/responses.yaml#/components/responses/SharedConfig"
401:
$ref: "../components/responses.yaml#/components/responses/NotAuthorized"

/api/v2/test/errors:
get:
tags:
- Test errors
parameters:
- name: fail
in: query
description: Fail
required: false
schema:
$ref: "../components/models.yaml#/components/schemas/FailingPoint"
responses:
200:
description: Success
default:
$ref: "../components/responses.yaml#/components/responses/ProblemDetails"
30 changes: 30 additions & 0 deletions api/gen.api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions api/gen.api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,21 @@ paths:
summary: Get operations for user
tags:
- Operations
/api/v2/test/errors:
get:
parameters:
- description: Fail
in: query
name: fail
schema:
$ref: '#/components/schemas/models_FailingPoint'
responses:
"200":
description: Success
default:
$ref: '#/components/responses/responses_ProblemDetails'
tags:
- Test errors
/api/v2/transactions:
post:
description: This endpoint allows to record transaction outline for authenticated user
Expand Down Expand Up @@ -381,6 +396,12 @@ components:
schema:
$ref: '#/components/schemas/errors_AdminAuthorization'
description: Security requirements failed
responses_ProblemDetails:
content:
application/json:
schema:
$ref: '#/components/schemas/errors_ProblemDetails'
description: Internal server error
responses_RecordTransactionBadRequest:
content:
application/json:
Expand Down Expand Up @@ -590,6 +611,24 @@ components:
message:
example: inconsistent paymail address and alias/domain
type: object
errors_ProblemDetails:
properties:
detail:
description: A human-readable explanation specific to this occurrence of the problem
type: string
instance:
description: A URI reference that identifies the specific occurrence of the problem
type: string
status:
description: The HTTP status code
type: integer
title:
description: A short, human-readable summary of the problem type
type: string
type:
description: A URI reference that identifies the problem type
type: string
type: object
errors_Schema:
additionalProperties: false
properties:
Expand Down Expand Up @@ -759,6 +798,17 @@ components:
required:
- bucket
type: object
models_FailingPoint:
enum:
- db_connection
- db_query
- domain_illegal_argument
- client_wrong_input
- client_auth_wrong
- client_auth_missing
- internal_during_auth
- arc_double_spent_attempt
type: string
models_InputAnnotation:
properties:
customInstructions:
Expand Down
42 changes: 42 additions & 0 deletions api/gen.models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 60 additions & 0 deletions engine/spverrors/examplecode/clienterr/builder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package clienterr

import (
"fmt"
"strings"

"github.com/bitcoin-sv/spv-wallet/engine/spverrors/examplecode/errdef"
"github.com/gin-gonic/gin"
"github.com/joomcode/errorx"
"github.com/rs/zerolog"
)

var propProblemDetails = errorx.RegisterProperty("problem_details")
var clientError = errorx.NewNamespace("client").NewType("error")

type Builder struct {
from *ClientErrorDefinition
problemDetails errdef.ProblemDetails
cause error
}

func (b *Builder) Wrap(cause error, msg string, args ...any) *Builder {
b.cause = cause
b.problemDetails.
FromInternalError(cause).
PushDetail(fmt.Sprintf(msg, args...))

return b
}

func (b *Builder) Err() *errorx.Error {
var err *errorx.Error
if b.cause != nil {
err = clientError.Wrap(b.cause, "")
} else {
err = clientError.NewWithNoMessage()
}
return err.WithProperty(propProblemDetails, b.problemDetails)
}

func (b *Builder) Response(c *gin.Context, log *zerolog.Logger) {
Response(c, b.Err(), log)
}

func (b *Builder) WithDetailf(detail string, args ...any) *Builder {
b.problemDetails.PushDetail(fmt.Sprintf(detail, args...))
return b
}

func (b *Builder) WithInstance(parts ...any) *Builder {
var sb strings.Builder
for i, p := range parts {
sb.WriteString(fmt.Sprintf("%v", p))
if i < len(parts)-1 {
sb.WriteString("/")
}
}
b.problemDetails.Instance = sb.String()
return b
}
Loading
Loading