Skip to content

Commit d6038e0

Browse files
committed
minor refactor: rename STATUS_CODE_ABORT => STATUS_CODE_THROW_ABORT
1 parent 1bd50cc commit d6038e0

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

packages/telefunc/client/remoteTelefunctionCall/makeHttpRequest.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { parse } from '@brillout/json-serializer/parse'
44
import { assert, assertUsage, isObject, objectAssign } from '../utils.js'
55
import { callOnAbortListeners } from './onAbort.js'
66
import {
7-
STATUS_CODE_ABORT,
7+
STATUS_CODE_THROW_ABORT,
88
STATUS_CODE_INTERNAL_SERVER_ERROR,
99
STATUS_CODE_MALFORMED_REQUEST,
1010
STATUS_CODE_SHIELD_VALIDATION_ERROR,
@@ -45,7 +45,7 @@ async function makeHttpRequest(callContext: {
4545
const { ret } = await parseResponseBody(response, callContext)
4646
const telefunctionReturn = ret
4747
return { telefunctionReturn }
48-
} else if (statusCode === STATUS_CODE_ABORT) {
48+
} else if (statusCode === STATUS_CODE_THROW_ABORT) {
4949
const { ret } = await parseResponseBody(response, callContext)
5050
const abortValue = ret
5151
const telefunctionCallError = new Error(
@@ -98,7 +98,7 @@ async function parseResponseBody(response: Response, callContext: { telefuncUrl:
9898
const responseBody = await response.text()
9999
const responseBodyParsed = parse(responseBody)
100100
assertUsage(isObject(responseBodyParsed) && 'ret' in responseBodyParsed, wrongInstallation({ method, callContext }))
101-
assert(response.status !== STATUS_CODE_ABORT || 'abort' in responseBodyParsed)
101+
assert(response.status !== STATUS_CODE_THROW_ABORT || 'abort' in responseBodyParsed)
102102
const { ret } = responseBodyParsed
103103
return { ret }
104104
}

packages/telefunc/node/server/runTelefunc.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ import { callBugListeners } from './runTelefunc/onBug.js'
1313
import { applyShield } from './runTelefunc/applyShield.js'
1414
import { findTelefunction } from './runTelefunc/findTelefunction.js'
1515
import { getServerConfig } from './serverConfig.js'
16-
import { STATUS_CODE_ABORT, STATUS_CODE_SHIELD_VALIDATION_ERROR } from '../../shared/constants.js'
16+
import {
17+
STATUS_CODE_THROW_ABORT,
18+
STATUS_CODE_SHIELD_VALIDATION_ERROR,
19+
STATUS_CODE_INTERNAL_SERVER_ERROR,
20+
STATUS_CODE_MALFORMED_REQUEST,
21+
STATUS_CODE_SUCCESS,
22+
} from '../../shared/constants.js'
1723

1824
/** The HTTP Response of a telefunction remote call HTTP Request */
1925
type HttpResponse = {
@@ -46,23 +52,23 @@ const shieldValidationError = {
4652
// - The Telefunc code threw an error (i.e. Telefunc has a bug).
4753
const serverError = {
4854
// TODO dedupe
49-
statusCode: 500 as const, // "Internal Server Error"
55+
statusCode: STATUS_CODE_INTERNAL_SERVER_ERROR,
5056
// TODO dedupe
5157
body: 'Internal Server Error',
5258
contentType: 'text/plain' as const,
5359
etag: null,
54-
}
60+
} as const
5561

5662
// HTTP Response for:
5763
// - Some non-telefunc client makes a malformed HTTP request.
5864
// - The telefunction couldn't be found.
5965
const malformedRequest = {
60-
statusCode: 400 as const, // "Bad Request"
66+
statusCode: STATUS_CODE_MALFORMED_REQUEST,
6167
// TODO dedupe
6268
body: 'Malformed Telefunc Request',
6369
contentType: 'text/plain' as const,
6470
etag: null,
65-
}
71+
} as const
6672

6773
async function runTelefunc(runContext: Parameters<typeof runTelefunc_>[0]): Promise<HttpResponse> {
6874
try {
@@ -174,7 +180,7 @@ async function runTelefunc_(httpRequest: {
174180
// }
175181

176182
return {
177-
statusCode: runContext.telefunctionAborted ? STATUS_CODE_ABORT : 200,
183+
statusCode: runContext.telefunctionAborted ? STATUS_CODE_THROW_ABORT : STATUS_CODE_SUCCESS,
178184
body: runContext.httpResponseBody,
179185
contentType: 'text/plain',
180186
// etag: runContext.httpResponseEtag,

packages/telefunc/shared/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ export const STATUS_CODE_MALFORMED_REQUEST = 400
44
* HTTP Response for:
55
* - `throw Abort()`
66
*/
7-
export const STATUS_CODE_ABORT = 403 // "Forbidden"
7+
export const STATUS_CODE_THROW_ABORT = 403 // "Forbidden"
88
export const STATUS_CODE_SHIELD_VALIDATION_ERROR = 422 // "Unprocessable Content"
99
export const STATUS_CODE_INTERNAL_SERVER_ERROR = 500

0 commit comments

Comments
 (0)