Created
September 21, 2022 12:28
-
-
Save bogdan/9054900fb6b547872364b69ed1ee0bf4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/backend/lib/routes/resellers/v1/DomainActionsController.ts b/backend/lib/routes/resellers/v1/DomainActionsController.ts | |
index 2f62cdcc73..1d2135ff2c 100644 | |
--- a/backend/lib/routes/resellers/v1/DomainActionsController.ts | |
+++ b/backend/lib/routes/resellers/v1/DomainActionsController.ts | |
@@ -64,14 +64,14 @@ const DomainActionsController = { | |
res: Response<DomainActionResponse>, | |
) => { | |
if (await isInvalidGetOneRequest(req)) { | |
- throw new HttpError.BadRequest('Invalid request'); | |
+ throw new ResellerApiError('REQUEST_INVALID', 'Invalid request'); | |
} | |
const action = await DomainAction.findOne({ | |
where: {id: req.params.id}, | |
}); | |
if (!action) { | |
- throw new HttpError.NotFound('DomainAction not found'); | |
+ throw new ResellerApiError('BLOCKCHAIN_ACTION_NOT_FOUND', 'Action not found', 'id', 404); | |
} | |
res.json(await serializeDomainAction(action)); | |
@@ -82,7 +82,7 @@ const DomainActionsController = { | |
res: Response<DomainActionResponse>, | |
) => { | |
if (await isInvalidPostRequest(req)) { | |
- throw new HttpError.BadRequest('Invalid request'); | |
+ throw new ResellerApiError('REQUEST_INVALID', 'Invalid request'); | |
} | |
const bridgeToPolygonEnabled = await FeatureFlag.isEnabled( | |
Features.BridgeToPolygonEnabled, | |
@@ -91,17 +91,17 @@ const DomainActionsController = { | |
const body = req.body; | |
const domain = await Domain.findOne({name: body.domain}); | |
if (!domain) { | |
- throw new HttpError.NotFound('Domain not found'); | |
+ throw new ResellerApiError('DOMAIN_NOT_FOUND', 'Domain not found', 'domain', 404); | |
} | |
const mirrorUpToDate = await isMirrorUpToDate(domain.blockchain()!); | |
if (!mirrorUpToDate) { | |
- throw new HttpError.InternalServerError('Unacceptable mirror delay'); | |
+ throw new ResellerApiError('UNACCEPTIBLE_MIRROR_DELAY', 'Unacceptable mirror delay', undefined, 500); | |
} | |
const user = await domain.ownerUser(); | |
if (!user) { | |
- throw new HttpError.BadRequest('Domain has no owner'); | |
+ throw new ResellerApiError('DOMAIN_UNMINTED', 'Domain has no owner', 'domain'); | |
} | |
const actions = await DomainAction.findDraftOrInProgressFor(domain); | |
@@ -116,9 +116,7 @@ const DomainActionsController = { | |
} | |
if (!bridgeToPolygonEnabled && !user.dev) { | |
- throw new HttpError.BadRequest( | |
- 'Polygon bridge is disabled at the moment.', | |
- ); | |
+ throw new ResellerApiError('BRIDGE_DISABLED', 'Polygon bridge is disabled at the moment.'); | |
} | |
let action; | |
@@ -130,13 +128,14 @@ const DomainActionsController = { | |
}); | |
} catch (error) { | |
if (error instanceof DomainActionValidationError) { | |
- throw new HttpError.BadRequest(error.message); | |
+ throw new ResellerApiError('BLOCKCHAIN_ACTION_INVALID', error.message); | |
} | |
throw error; | |
} | |
if (!(await action.txs).length) { | |
- throw new HttpError.BadRequest( | |
+ throw new ResellerApiError( | |
+ 'BLOCKCHAIN_ACTION_USELESS', | |
'Action will not cause any changes on chain', | |
); | |
} | |
@@ -165,7 +164,7 @@ const DomainActionsController = { | |
res: Response<void>, | |
) => { | |
if (!(await isValidPostSignRequest(req))) { | |
- throw new HttpError.BadRequest('Invalid request'); | |
+ throw new ResellerApiError('REQUEST_INVALID', 'Invalid request'); | |
} | |
const body = req.body; | |
@@ -173,7 +172,7 @@ const DomainActionsController = { | |
where: {id: req.params.id}, | |
}); | |
if (!action) { | |
- throw new HttpError.NotFound('DomainAction not found'); | |
+ throw new ResellerApiError('BLOCKCHAIN_ACTION_NOT_FOUND', 'Action not found', 'id', 404); | |
} | |
if (action.stripeIntent) { | |
@@ -181,7 +180,7 @@ const DomainActionsController = { | |
await findPaymentIntent(action.stripeIntent); | |
if (paymentIntent.status !== 'succeeded') { | |
- throw new HttpError.BadRequest('Domain action is not paid for'); | |
+ throw new ResellerApiError('BLOCKCHAIN_ACTION_UNPAID', 'Domain action is not paid for'); | |
} | |
} | |
@@ -191,7 +190,7 @@ const DomainActionsController = { | |
// We don't want to notify Bugsnag here yet, as it can be an expected validation error. | |
logger.warn(err); | |
if (err instanceof DomainActionValidationError) { | |
- throw new HttpError.BadRequest(err.message); | |
+ throw new ResellerApiError('BLOCKCHAIN_ACTION_INVALID', err.message); | |
} | |
throw err; | |
} | |
@@ -210,13 +209,13 @@ async function parsedQsToQueryParams(query: DomainActionParsedQs) { | |
validateDomainName(query.domain); | |
const domain = await Domain.findOne({name: query.domain}); | |
if (!domain) { | |
- throw new HttpError.BadRequest('Domain is not found'); | |
+ throw new ResellerApiError('DOMAIN_NOT_FOUND', 'Domain not found', 'domain', 404); | |
} | |
return {...queryParams, domainId: domain.id}; | |
} else if ('userId' in query && typeof query.userId === 'string') { | |
const user = await User.findOne({id: Number(query.userId)}); | |
if (!user) { | |
- throw new HttpError.BadRequest('User is not found'); | |
+ throw new ResellerApiError('USER_NOT_FOUND', 'User is not found', 'userId', 404); | |
} | |
return {...queryParams, userId: user.id}; | |
} else if ( | |
@@ -229,7 +228,8 @@ async function parsedQsToQueryParams(query: DomainActionParsedQs) { | |
: [query.ownerAddress]; | |
return {...queryParams, ownerAddresses: ownerAddresses as string[]}; | |
} else { | |
- throw new HttpError.BadRequest( | |
+ throw new ResellerApiError( | |
+ 'QUERY_ARGUMENT_REQUIRED', | |
"Either 'userId', 'domain', or 'ownerAddress' argument must be supplied", | |
); | |
} | |
diff --git a/client/actions/blockchainDomainActions.ts b/client/actions/blockchainDomainActions.ts | |
index c46f7a5d4a..effd1375ad 100644 | |
--- a/client/actions/blockchainDomainActions.ts | |
+++ b/client/actions/blockchainDomainActions.ts | |
@@ -48,7 +48,7 @@ export const getDomainActions = async ( | |
count: number; | |
actions: DomainActionsResponseItem[]; | |
}> => { | |
- return fetchApi(`/v1/resellers/frontend/actions`, { | |
+ return fetchApi(`/v2/resellers/frontend/actions`, { | |
auth: false, | |
method: 'GET', | |
headers: new Headers({ | |
@@ -63,7 +63,7 @@ export const getDomainAction = async ( | |
id: number, | |
): Promise<DomainActionResponse | undefined> => { | |
return fetchApi<DomainActionResponse>( | |
- `/v1/resellers/frontend/actions/${id}`, | |
+ `/v2/resellers/frontend/actions/${id}`, | |
{ | |
auth: false, | |
method: 'GET', | |
@@ -90,7 +90,7 @@ export const postDomainAction = async <T extends BlockchainActionType>( | |
...actionPayload, | |
}; | |
- return fetchApi<DomainActionResponse>(`/v1/resellers/frontend/actions`, { | |
+ return fetchApi<DomainActionResponse>(`/v2/resellers/frontend/actions`, { | |
auth: false, | |
method: 'POST', | |
headers: new Headers({ | |
@@ -105,7 +105,7 @@ export const postSignDomainActions = async ( | |
domainActionId: number, | |
txs: DomainActionTxInput[], | |
): Promise<void> => { | |
- await fetchApi(`/v1/resellers/frontend/actions/${domainActionId}/sign`, { | |
+ await fetchApi(`/v2/resellers/frontend/actions/${domainActionId}/sign`, { | |
auth: false, | |
method: 'POST', | |
headers: new Headers({ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment