Skip to content

Commit

Permalink
refactor(actions-service.ts): replace GraphQLError with custom throwA…
Browse files Browse the repository at this point in the history
…ctionStateError function to centralize error handling and improve code readability
  • Loading branch information
MartinMinkov committed Feb 23, 2024
1 parent e33c2e6 commit d13751c
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions src/services/actions-service/actions-service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type postgres from 'postgres';

import { GraphQLError } from 'graphql';
import {
BlockStatusFilter,
BlocksWithTransactionsMap,
Expand All @@ -27,6 +26,7 @@ import {
TracingState,
extractTraceStateFromOptions,
} from '../../tracing/tracer.js';
import { throwActionStateError } from '../../errors/error.js';

export { ActionsService };

Expand Down Expand Up @@ -75,14 +75,8 @@ class ActionsService implements IActionsService {
fromActionState
);
if (!fromActionStateExists || !fromActionStateExists.length) {
throw new GraphQLError(
`fromActionState ${fromActionState} does not exist`,
{
extensions: {
code: 'ACTION_STATE_NOT_FOUND',
status: 400,
},
}
throwActionStateError(
`fromActionState ${fromActionState} does not exist`
);
}
}
Expand All @@ -92,14 +86,8 @@ class ActionsService implements IActionsService {
endActionState
);
if (!endActionStateExists || !endActionStateExists.length) {
throw new GraphQLError(
`endActionState ${endActionState} does not exist`,
{
extensions: {
code: 'ACTION_STATE_NOT_FOUND',
status: 400,
},
}
throwActionStateError(
`endActionState ${endActionState} does not exist`
);
}
}
Expand Down

0 comments on commit d13751c

Please sign in to comment.