Skip to content

Commit

Permalink
fix: replaced error codes
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavkparti committed Sep 6, 2023
1 parent e94f1f5 commit a5d2ec8
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
22 changes: 11 additions & 11 deletions server/models/Transfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class Transfer {
}
if (token.claim) {
throw new HttpError(
403,
409,
`The token ${token.id} is claimed, cannot be transfered`,
);
}
Expand Down Expand Up @@ -242,7 +242,7 @@ class Transfer {
// }
// console.log(notClaimedTokenCount);
if (notClaimedTokenCount < bundleSize) {
throw new HttpError(403, `Do not have enough tokens to send`);
throw new HttpError(409, `Do not have enough tokens to send`);
}

const isDeduct = await this.isDeduct(walletLoginId, sender);
Expand Down Expand Up @@ -336,7 +336,7 @@ class Transfer {
const transfer = await this._transferRepository.getById(transferId);
const receiverId = transfer.destination_wallet_id;
if (transfer.state !== TransferEnums.STATE.pending) {
throw new HttpError(403, 'The transfer state is not pending');
throw new HttpError(409, 'The transfer state is not pending');
}
const doesCurrentAccountHasControlOverReceiver = await this._wallet.hasControlOver(
walletLoginId,
Expand All @@ -362,7 +362,7 @@ class Transfer {
bundleSize,
);
if (tokens.length < bundleSize) {
throw new HttpError(403, 'Do not have enough tokens');
throw new HttpError(409, 'Do not have enough tokens');
}
await this._token.completeTransfer(tokens, transfer);
} else {
Expand All @@ -388,7 +388,7 @@ class Transfer {
transfer.state !== TransferEnums.STATE.requested
) {
throw new HttpError(
403,
409,
'The transfer state is neither pending nor requested',
);
}
Expand Down Expand Up @@ -433,7 +433,7 @@ class Transfer {
transfer.state !== TransferEnums.STATE.requested
) {
throw new HttpError(
403,
409,
'The transfer state is neither pending nor requested',
);
}
Expand Down Expand Up @@ -489,7 +489,7 @@ class Transfer {
}
if (transfer.state !== TransferEnums.STATE.requested) {
throw new HttpError(
403,
409,
'Operation forbidden, the transfer state is wrong',
);
}
Expand Down Expand Up @@ -533,7 +533,7 @@ class Transfer {
}
if (transfer.state !== TransferEnums.STATE.requested) {
throw new HttpError(
403,
409,
'Operation forbidden, the transfer state is wrong',
);
}
Expand All @@ -547,14 +547,14 @@ class Transfer {
// check it
if (tokens.length > bundleSize) {
throw new HttpError(
403,
409,
`Too many tokens to transfer, please provider ${bundleSize} tokens for this transfer`,
true,
);
}
if (tokens.length < bundleSize) {
throw new HttpError(
403,
409,
`Too few tokens to transfer, please provider ${bundleSize} tokens for this transfer`,
true,
);
Expand All @@ -573,7 +573,7 @@ class Transfer {
// transfer
await this._token.completeTransfer(tokens, transfer);
} else {
throw new HttpError(403, 'No need to specify tokens', true);
throw new HttpError(409, 'No need to specify tokens', true);
}
return transferJson;
}
Expand Down
2 changes: 1 addition & 1 deletion server/models/Trust.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class Trust {
) {
log.debug('Has duplicated trust');
throw new HttpError(
403,
409,
'The trust relationship has been requested or trusted',
);
}
Expand Down
2 changes: 1 addition & 1 deletion server/models/Wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Wallet {
// check name
try {
await this._walletRepository.getByName(wallet);
throw new HttpError(403, `The wallet '${wallet}' already exists`);
throw new HttpError(409, `The wallet '${wallet}' already exists`);
} catch (e) {
if (e instanceof HttpError && e.code === 404) {
// fine
Expand Down
8 changes: 4 additions & 4 deletions server/services/JWTService.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class JWTService {
static verify(authorization) {
if (!authorization) {
throw new HttpError(
403,
401,
'ERROR: Authentication, no token supplied for protected path',
);
}
Expand All @@ -43,17 +43,17 @@ class JWTService {
JWTTools.verify(token, publicKEY, verifyOptions, (err, decod) => {
if (err || tokenArray[0] !== 'Bearer') {
log.debug(err);
throw new HttpError(403, 'ERROR: Authentication, token not verified');
throw new HttpError(401, 'ERROR: Authentication, token not verified');
}
result = decod;
if (!result.id)
throw new HttpError(
403,
401,
'ERROR: Authentication, invalid token received',
);
});
} else {
throw new HttpError(403, 'ERROR: Authentication, token not verified');
throw new HttpError(401, 'ERROR: Authentication, token not verified');
}
return result;
}
Expand Down
2 changes: 1 addition & 1 deletion server/services/TokenService.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class TokenService {

const walletIds = [...allWallets.map((e) => e.id)];
if (!walletIds.includes(token.wallet_id)) {
throw new HttpError(401, 'Have no permission to visit this token');
throw new HttpError(403, 'Have no permission to visit this token');
}
}

Expand Down

0 comments on commit a5d2ec8

Please sign in to comment.