Skip to content

Commit 713c9ba

Browse files
authored
Merge pull request #422 from pranavkparti/error-code-fixes
Error code fixes
2 parents 83a2184 + bac90e7 commit 713c9ba

File tree

13 files changed

+153
-94
lines changed

13 files changed

+153
-94
lines changed

__tests__/get-tokens.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describe('GET tokens', () => {
6262
.get(`/tokens/${seed.tokenB.id}`)
6363
.set('treetracker-api-key', seed.apiKey)
6464
.set('Authorization', `Bearer ${bearerToken}`);
65-
expect(res).to.have.property('statusCode', 401);
65+
expect(res).to.have.property('statusCode', 403);
6666
});
6767

6868
it(`walletA, GET /tokens Should be able to get a token `, async () => {

docs/api/spec/treetracker-wallet-api.yaml

Lines changed: 115 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ openapi: 3.0.0
22
info:
33
title: Treetracker Wallet API
44
contact: {}
5-
version: '1.27.4'
5+
version: '1.28.0'
66
servers:
77
- url: https://{environment}-k8s.treetracker.org/wallet/v2
88
variables:
@@ -118,8 +118,6 @@ paths:
118118
$ref: '#/components/schemas/tokens'
119119
'401':
120120
$ref: '#/components/responses/UnauthorizedError'
121-
'403':
122-
$ref: '#/components/responses/ForbiddenError'
123121
'422':
124122
description: 'Invalid or missing request parameters'
125123
content:
@@ -155,8 +153,6 @@ paths:
155153
$ref: '#/components/schemas/tokenItem'
156154
'401':
157155
$ref: '#/components/responses/UnauthorizedError'
158-
'403':
159-
$ref: '#/components/responses/ForbiddenError'
160156
'404':
161157
description: 'No token found matching token_uuid'
162158
content:
@@ -221,8 +217,6 @@ paths:
221217
$ref: '#/components/schemas/historyResponse'
222218
'401':
223219
$ref: '#/components/responses/UnauthorizedError'
224-
'403':
225-
$ref: '#/components/responses/ForbiddenError'
226220
'404':
227221
description: 'No token found matching token_uuid'
228222
content:
@@ -280,8 +274,6 @@ paths:
280274
$ref: '#/components/schemas/walletsResponse'
281275
'401':
282276
$ref: '#/components/responses/UnauthorizedError'
283-
'403':
284-
$ref: '#/components/responses/ForbiddenError'
285277
'422':
286278
description: 'Invalid query parameters'
287279
content:
@@ -324,8 +316,15 @@ paths:
324316
example: new_wallet
325317
'401':
326318
$ref: '#/components/responses/UnauthorizedError'
327-
'403':
328-
$ref: '#/components/responses/ForbiddenError'
319+
'409':
320+
description: 'The wallet to be created already exists'
321+
content:
322+
application/json:
323+
schema:
324+
$ref: '#/components/schemas/errorResponse'
325+
example:
326+
code: 409
327+
message: 'The wallet "walletX" already exists'
329328
'415':
330329
$ref: '#/components/responses/UnsupportedMediaTypeError'
331330
'422':
@@ -379,8 +378,6 @@ paths:
379378
example: 12
380379
'401':
381380
$ref: '#/components/responses/UnauthorizedError'
382-
'403':
383-
$ref: '#/components/responses/ForbiddenError'
384381
'404':
385382
$ref: '#/components/responses/walletNotFound'
386383
'422':
@@ -417,8 +414,6 @@ paths:
417414
$ref: '#/components/schemas/trustRelationshipsResponse'
418415
'401':
419416
$ref: '#/components/responses/UnauthorizedError'
420-
'403':
421-
$ref: '#/components/responses/ForbiddenError'
422417
'404':
423418
$ref: '#/components/responses/walletNotFound'
424419
'422':
@@ -459,7 +454,14 @@ paths:
459454
'401':
460455
$ref: '#/components/responses/UnauthorizedError'
461456
'403':
462-
$ref: '#/components/responses/ForbiddenError'
457+
description: 'Lacking permission to transfer the tokens'
458+
content:
459+
application/json:
460+
schema:
461+
$ref: '#/components/schemas/errorResponse'
462+
example:
463+
code: 403
464+
message: 'The token 89b071ee-c49d-420c-b43d-0d3dfe323962 does not belong to the sender wallet'
463465
'404':
464466
description: 'No wallet or token found matching the corresponding parameters'
465467
content:
@@ -469,6 +471,15 @@ paths:
469471
example:
470472
code: 404
471473
message: 'Could not find entity by wallet name: testwalletxyz'
474+
'409':
475+
description: 'The transfer cannot be processed due to some conflict'
476+
content:
477+
application/json:
478+
schema:
479+
$ref: '#/components/schemas/errorResponse'
480+
example:
481+
code: 409
482+
message: 'The token 89b071ee-c49d-420c-b43d-0d3dfe32396 is claimed, cannot be transfered'
472483
'415':
473484
$ref: '#/components/responses/UnsupportedMediaTypeError'
474485
'422':
@@ -567,8 +578,6 @@ paths:
567578
example: 1
568579
'401':
569580
$ref: '#/components/responses/UnauthorizedError'
570-
'403':
571-
$ref: '#/components/responses/ForbiddenError'
572581
'422':
573582
description: 'Invalid query parameters'
574583
content:
@@ -600,8 +609,6 @@ paths:
600609
$ref: '#/components/schemas/transferItem'
601610
'401':
602611
$ref: '#/components/responses/UnauthorizedError'
603-
'403':
604-
$ref: '#/components/responses/ForbiddenError'
605612
'404':
606613
description: 'No transfer found matching the transfer_id or the transfer is not associated with the logged in wallet'
607614
content:
@@ -623,8 +630,8 @@ paths:
623630
delete:
624631
tags:
625632
- Transfers
626-
summary: Cancel a pending or requested transfer that has not closed
627-
description: Cancel a pending (untrusted) or requested transfer. The executor can delete the pending/requested transfer before it is executed. Transfer is marked canceled by this command.
633+
summary: 'Cancel a pending or requested transfer that has not closed'
634+
description: 'Cancel a pending (untrusted) or requested transfer. The executor can delete the pending/requested transfer before it is executed. Transfer is marked canceled by this command.'
628635
parameters:
629636
- $ref: '#/components/parameters/treetrackerApiKeyParam'
630637
- name: transfer_id
@@ -638,8 +645,6 @@ paths:
638645
$ref: '#/components/responses/transferCancelledResponse'
639646
'401':
640647
$ref: '#/components/responses/UnauthorizedError'
641-
'403':
642-
$ref: '#/components/responses/ForbiddenError'
643648
'404':
644649
description: 'No transfer found matching the transfer_id or the transfer is not associated with the logged in wallet'
645650
content:
@@ -649,8 +654,15 @@ paths:
649654
example:
650655
code: 404
651656
message: 'Can not found transfer by id:03537683-5356-42f4-97b2-95ba287a453b'
652-
'406':
653-
description: 'Transfer with this id is not in requested or pending state'
657+
'409':
658+
description: 'Transfer could not be cancelled due to some conflict'
659+
content:
660+
application/json:
661+
schema:
662+
$ref: '#/components/schemas/errorResponse'
663+
example:
664+
code: 409
665+
message: 'The transfer state is neither pending nor requested'
654666
'/transfers/{transfer_id}/tokens':
655667
get:
656668
tags:
@@ -699,8 +711,6 @@ paths:
699711
$ref: '#/components/schemas/transferTokenItem'
700712
'401':
701713
$ref: '#/components/responses/UnauthorizedError'
702-
'403':
703-
$ref: '#/components/responses/ForbiddenError'
704714
'404':
705715
description: 'No transfer found matching the transfer_id or the transfer is not associated with the logged in wallet'
706716
content:
@@ -739,7 +749,14 @@ paths:
739749
'401':
740750
$ref: '#/components/responses/UnauthorizedError'
741751
'403':
742-
$ref: '#/components/responses/ForbiddenError'
752+
description: 'Lacking permission to accept the transfer'
753+
content:
754+
application/json:
755+
schema:
756+
$ref: '#/components/schemas/errorResponse'
757+
example:
758+
code: 403
759+
message: 'Current account has no permission to accept this transfer'
743760
'404':
744761
description: 'No transfer found matching the transfer_id or the transfer is not associated with the logged in wallet'
745762
content:
@@ -749,6 +766,15 @@ paths:
749766
example:
750767
code: 404
751768
message: 'Can not found transfer by id:df80b648-4fef-4ca6-b704-9e7e1c77d1ef'
769+
'409':
770+
description: 'Transfer could not be processed due to some conflict'
771+
content:
772+
application/json:
773+
schema:
774+
$ref: '#/components/schemas/errorResponse'
775+
example:
776+
code: 409
777+
message: 'Do not have enough tokens'
752778
'415':
753779
$ref: '#/components/responses/UnsupportedMediaTypeError'
754780
'422':
@@ -780,7 +806,14 @@ paths:
780806
'401':
781807
$ref: '#/components/responses/UnauthorizedError'
782808
'403':
783-
$ref: '#/components/responses/ForbiddenError'
809+
description: 'Lacking permission to decline the transfer'
810+
content:
811+
application/json:
812+
schema:
813+
$ref: '#/components/schemas/errorResponse'
814+
example:
815+
code: 403
816+
message: 'Current account has no permission to decline this transfer'
784817
'404':
785818
description: 'No transfer found matching the transfer_id or the transfer is not associated with the logged in wallet'
786819
content:
@@ -790,6 +823,15 @@ paths:
790823
example:
791824
code: 404
792825
message: 'Can not found transfer by id:df80b648-4fef-4ca6-b704-9e7e1c77d1ef'
826+
'409':
827+
description: 'Transfer could not be processed due to some conflict'
828+
content:
829+
application/json:
830+
schema:
831+
$ref: '#/components/schemas/errorResponse'
832+
example:
833+
code: 409
834+
message: 'The transfer state is neither pending nor requested'
793835
'415':
794836
$ref: '#/components/responses/UnsupportedMediaTypeError'
795837
'422':
@@ -828,7 +870,14 @@ paths:
828870
'401':
829871
$ref: '#/components/responses/UnauthorizedError'
830872
'403':
831-
$ref: '#/components/responses/ForbiddenError'
873+
description: 'Lacking permission to fulfill the transfer'
874+
content:
875+
application/json:
876+
schema:
877+
$ref: '#/components/schemas/errorResponse'
878+
example:
879+
code: 403
880+
message: 'Current account has no permission to decline this transfer'
832881
'404':
833882
description: 'No transfer found matching the transfer_id or the transfer is not associated with the logged in wallet'
834883
content:
@@ -838,6 +887,15 @@ paths:
838887
example:
839888
code: 404
840889
message: 'Can not found transfer by id:df80b648-4fef-4ca6-b704-9e7e1c77d1ef'
890+
'409':
891+
description: 'Transfer could not be processed due to some conflict'
892+
content:
893+
application/json:
894+
schema:
895+
$ref: '#/components/schemas/errorResponse'
896+
example:
897+
code: 409
898+
message: 'Operation forbidden, the transfer state is wron'
841899
'415':
842900
$ref: '#/components/responses/UnsupportedMediaTypeError'
843901
'422':
@@ -907,8 +965,6 @@ paths:
907965
$ref: '#/components/schemas/trustRelationshipsResponse'
908966
'401':
909967
$ref: '#/components/responses/UnauthorizedError'
910-
'403':
911-
$ref: '#/components/responses/ForbiddenError'
912968
'422':
913969
description: 'Invalid query parameters'
914970
content:
@@ -940,7 +996,14 @@ paths:
940996
'401':
941997
$ref: '#/components/responses/UnauthorizedError'
942998
'403':
943-
$ref: '#/components/responses/ForbiddenError'
999+
description: 'Lacking permission to create the trust relationship'
1000+
content:
1001+
application/json:
1002+
schema:
1003+
$ref: '#/components/schemas/errorResponse'
1004+
example:
1005+
code: 403
1006+
message: 'Have no permission to deal with this actor'
9441007
'415':
9451008
$ref: '#/components/responses/UnsupportedMediaTypeError'
9461009
'422':
@@ -975,8 +1038,6 @@ paths:
9751038
$ref: '#/components/schemas/trustRelationshipItem'
9761039
'401':
9771040
$ref: '#/components/responses/UnauthorizedError'
978-
'403':
979-
$ref: '#/components/responses/ForbiddenError'
9801041
'404':
9811042
$ref: '#/components/responses/trustRelationshipNotFound'
9821043
'422':
@@ -1027,7 +1088,14 @@ paths:
10271088
'401':
10281089
$ref: '#/components/responses/UnauthorizedError'
10291090
'403':
1030-
$ref: '#/components/responses/ForbiddenError'
1091+
description: 'Lacking permission to cancel the trust relationship'
1092+
content:
1093+
application/json:
1094+
schema:
1095+
$ref: '#/components/schemas/errorResponse'
1096+
example:
1097+
code: 403
1098+
message: 'Have no permission to cancel this relationship'
10311099
'404':
10321100
$ref: '#/components/responses/trustRelationshipNotFound'
10331101
'422':
@@ -1077,8 +1145,6 @@ paths:
10771145
target_wallet: testWallet11
10781146
'401':
10791147
$ref: '#/components/responses/UnauthorizedError'
1080-
'403':
1081-
$ref: '#/components/responses/ForbiddenError'
10821148
'404':
10831149
$ref: '#/components/responses/trustRelationshipNotFound'
10841150
'415':
@@ -1130,8 +1196,6 @@ paths:
11301196
target_wallet: testWallet11
11311197
'401':
11321198
$ref: '#/components/responses/UnauthorizedError'
1133-
'403':
1134-
$ref: '#/components/responses/ForbiddenError'
11351199
'404':
11361200
$ref: '#/components/responses/trustRelationshipNotFound'
11371201
'415':
@@ -1683,23 +1747,20 @@ components:
16831747
type: string
16841748
responses:
16851749
UnauthorizedError:
1686-
description: API key is missing or invalid or missing
1687-
content:
1688-
application/json:
1689-
schema:
1690-
$ref: '#/components/schemas/errorResponse'
1691-
example:
1692-
code: 401
1693-
message: 'Invalid access - no API key'
1694-
ForbiddenError:
1695-
description: 'Access bearer token is missing or invalid, or some permission is missing, etc.'
1750+
description: 'API key and/or Bearer token is missing or invalid'
16961751
content:
16971752
application/json:
16981753
schema:
16991754
$ref: '#/components/schemas/errorResponse'
1700-
example:
1701-
code: 403
1702-
message: 'ERROR: Authentication, no token supplied for protected path'
1755+
examples:
1756+
Invalid API Key:
1757+
value:
1758+
code: 401
1759+
message: 'Invalid access - no API key'
1760+
Invalid Bearer Token:
1761+
value:
1762+
code: 401
1763+
message: 'ERROR: Authentication, no token supplied for protected path'
17031764
UnsupportedMediaTypeError:
17041765
description: Invalid content type
17051766
content:

0 commit comments

Comments
 (0)