Skip to content

Commit

Permalink
improve sep-06 response 403 handling
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-rogobete committed Apr 23, 2024
1 parent 68e0d7a commit 33c12d7
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions lib/src/sep/0006/transfer_server_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,8 @@ class TransferServerService {
queryParams["location_id"] = request.locationId!;
}

DepositResponse response;
try {
response = await requestBuilder
return await requestBuilder
.forQueryParameters(queryParams)
.execute(request.jwt);
} on ErrorResponse catch (e) {
Expand All @@ -136,8 +135,6 @@ class TransferServerService {
}
throw e;
}

return response;
}

/// If the anchor supports SEP-38 quotes, it can provide a deposit that makes
Expand Down Expand Up @@ -206,8 +203,16 @@ class TransferServerService {
queryParams["location_id"] = request.locationId!;
}

return await requestBuilder.forQueryParameters(queryParams)
.execute(request.jwt);
try {
return await requestBuilder
.forQueryParameters(queryParams)
.execute(request.jwt);
} on ErrorResponse catch (e) {
if (e.code == 403) {
_handleForbiddenResponse(e);
}
throw e;
}
}

/// A withdraw is when a user redeems an asset currently on the
Expand Down Expand Up @@ -282,9 +287,8 @@ class TransferServerService {
queryParams["location_id"] = request.locationId!;
}

WithdrawResponse response;
try {
response = await requestBuilder
return await requestBuilder
.forQueryParameters(queryParams)
.execute(request.jwt);
} on ErrorResponse catch (e) {
Expand All @@ -293,7 +297,6 @@ class TransferServerService {
}
throw e;
}
return response;
}

/// If the anchor supports SEP-38 quotes, it can provide a withdraw that makes
Expand Down Expand Up @@ -368,8 +371,16 @@ class TransferServerService {
queryParams["location_id"] = request.locationId!;
}

return await requestBuilder.forQueryParameters(queryParams)
.execute(request.jwt);
try {
return await requestBuilder
.forQueryParameters(queryParams)
.execute(request.jwt);
} on ErrorResponse catch (e) {
if (e.code == 403) {
_handleForbiddenResponse(e);
}
throw e;
}
}

_handleForbiddenResponse(ErrorResponse e) {
Expand Down Expand Up @@ -2229,6 +2240,13 @@ class AnchorTransactionRequest {

/// jwt previously received from the anchor via the SEP-10 authentication flow
String? jwt;

AnchorTransactionRequest(
{this.id,
this.stellarTransactionId,
this.externalTransactionId,
this.lang,
this.jwt});
}

class AnchorTransactionResponse extends Response {
Expand Down

0 comments on commit 33c12d7

Please sign in to comment.