Start Here

Go error handling

Check three-value returns, read structured Core error codes, and handle validation and transport failures with the Go SDK.

Every SDK method returns three values: the result, the HTTP response, and an error.

Check err before you use the result. When err is nil, the result holds the decoded response. When err is set, the result is empty and you should handle the failure.

What each return value holds

txn, resp, err := client.Transaction.Get("txn_f482a1b3-6c2d-4e89-a17b-3d5e8f2a1c94")
Return valueContains
Result (txn)Decoded success body. Zero or nil when err is set.
*http.Response (resp)HTTP status, headers, and metadata. nil when validation fails before a request is sent.
error (err)Core HTTP failure (*ApiErrorResponse), client-side validation error, JSON decode error, or transport failure.

After you confirm err == nil, use the result and optionally log resp.StatusCode.

Core error types

When Core rejects a request, the SDK wraps the failure in *blnkgo.ApiErrorResponse. Use errors.As to read structured fields instead of parsing message text.

type ApiErrorDetail struct {
	Code    string
	Message string
	Details interface{}
}

type ApiErrorResponse struct {
	Status      int
	Message     string
	LegacyError string
	ErrorDetail *ApiErrorDetail
	Body        []byte
}
FieldDescription
StatusHTTP status code from Core (for example 404).
MessageHTTP status text (for example "404 Not Found").
LegacyErrorFlat "error" string from Core when present.
ErrorDetailStructured details parsed from error_detail. Read ErrorDetail.Code for routing.
BodyRaw JSON error payload from Core.

The SDK also exports blnkgo.AsApiErrorResponse(err) as a shortcut for errors.As.

How to handle errors

Check err

On every call, confirm err is nil before you use the result.

txn, resp, err := client.Transaction.Get("txn_f482a1b3-6c2d-4e89-a17b-3d5e8f2a1c94")
if err != nil {
	var apiErr *blnkgo.ApiErrorResponse
	if errors.As(err, &apiErr) {
		switch apiErr.Status {
		case http.StatusNotFound:
			// Check apiErr.ErrorDetail.Code (e.g. TXN_NOT_FOUND)
		case http.StatusUnauthorized, http.StatusForbidden:
			// Check the API key and scopes
		default:
			// Log apiErr.Status and apiErr.ErrorDetail.Code
		}
	}
	return err
}

// Use txn

Read the error detail

Use the field that matches the failure:

  • Core rejection: errors.As matches *ApiErrorResponse. Read apiErr.ErrorDetail.Code for logic. Use apiErr.Status when you only need broad handling (401, 404, 409, 5xx).
  • SDK validation: plain error before any HTTP call. Read err.Error() and fix the payload before retrying.

See API error codes for the full list of codes Core returns and what each one means.

Handle transport failures

When the SDK cannot reach Core or the request times out, you get a network or timeout error from the HTTP client. Configure timeout and logging in your SDK client.

What Core sends on rejection

When Core rejects a request, the response body looks like this:

{
  "error": "transaction not found",
  "error_detail": {
    "code": "TXN_NOT_FOUND",
    "message": "transaction not found"
  }
}

The SDK maps that JSON into ApiErrorResponse. Read apiErr.ErrorDetail.Code in your app, not the message string. Message text can change between releases.

The SDK exports these codes as constants:

ConstantWhen Core returns it
blnkgo.ErrorCodeTxnValidationErrorNegative amount or precision, or source equal to destination
blnkgo.ErrorCodeGenConflictDuplicate General Ledger indicator and currency (409)
blnkgo.ErrorCodeTxnInvalidAmountInvalid amount (see the API error codes catalog)

When Core returns only a flat "error" string with no error_detail, the SDK sets ErrorDetail.Code to "UNKNOWN".

Use apiErr.Status to pick the first branch (not found, auth, conflict, bad request, or server failure). Then use apiErr.ErrorDetail.Code for the specific case.

StatusWhen it happensWhat to do
404Resource ID or path does not existCheck apiErr.ErrorDetail.Code (e.g. TXN_NOT_FOUND, IDT_NOT_FOUND)
401 or 403API key, scope, or permission failureCheck the key, scopes, and whether the method requires the master key
409Conflict (duplicate reference, lock, or in-progress job)Retry only if the operation is safe to repeat
400Core rejected the payloadFix the request body before retrying
5xxCore or upstream failureRetry later and check Core logs

Client-side validation

Some methods validate input before sending a request. When validation fails, Core never receives the call.

Return valueValue
ResultZero value (nil for pointers)
*http.Responsenil
errorValidation message, e.g. reference field must be a valid string