Skip to content

Commit

Permalink
feat(repo): add status code to HTTPError type
Browse files Browse the repository at this point in the history
Errors of type HTTPError now have a status code field
  • Loading branch information
jwulf committed Apr 18, 2024
1 parent 7a8c696 commit 4ff2861
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 10 deletions.
2 changes: 0 additions & 2 deletions docker/docker-compose-modeler.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#
# Note: this file is using Mailpit to simulate a mail server

version: "2.4"

services:
modeler-db:
container_name: modeler-db
Expand Down
2 changes: 2 additions & 0 deletions src/__tests__/operate/operate-integration.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { HTTPError } from 'got'
import { RESTError } from 'lib'
import { LosslessNumber } from 'lossless-json'

Expand Down Expand Up @@ -92,6 +93,7 @@ test('test error type', async () => {
// `string`

expect((e.response?.body as string).includes('404')).toBe(true)
expect(e instanceof HTTPError).toBe(true)
return false
})
expect(res).toBe(false)
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/testdata/Operate-StraightThrough.bpmn
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
</bpmn:definitions>
10 changes: 5 additions & 5 deletions src/c8/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { ZeebeGrpcClient } from '../zeebe'
* import { Camunda8 } from '@camunda8/sdk'
*
* const c8 = new Camunda8()
* const zeebe = c8.getZeebeGrpcClient()
* const zeebe = c8.getZeebeGrpcApiClient()
* const operate = c8.getOperateApiClient()
* const optimize = c8.getOptimizeApiClient()
* const tasklist = c8.getTasklistApiClient()
Expand All @@ -35,7 +35,7 @@ export class Camunda8 {
private modelerApiClient?: ModelerApiClient
private optimizeApiClient?: OptimizeApiClient
private tasklistApiClient?: TasklistApiClient
private zeebeGrpcClient?: ZeebeGrpcClient
private zeebeGrpcApiClient?: ZeebeGrpcClient
private configuration: CamundaPlatform8Configuration
private oAuthProvider?: OAuthProvider

Expand Down Expand Up @@ -99,12 +99,12 @@ export class Camunda8 {
}

public getZeebeGrpcApiClient(): ZeebeGrpcClient {
if (!this.zeebeGrpcClient) {
this.zeebeGrpcClient = new ZeebeGrpcClient({
if (!this.zeebeGrpcApiClient) {
this.zeebeGrpcApiClient = new ZeebeGrpcClient({
config: this.configuration,
oAuthProvider: this.oAuthProvider,
})
}
return this.zeebeGrpcClient
return this.zeebeGrpcApiClient
}
}
2 changes: 1 addition & 1 deletion src/lib/GotErrors.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as Got from 'got'

export type RESTError =
| Got.HTTPError
| (Got.HTTPError & { statusCode: number })
| Got.RequestError
| Got.ReadError
| Got.ParseError
Expand Down
11 changes: 11 additions & 0 deletions src/lib/GotHooks.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { HTTPError } from 'got'

export const gotErrorHandler = (options, next) => {
if (Object.isFrozen(options.context)) {
options.context = { ...options.context }
Expand All @@ -12,5 +14,14 @@ export const gotBeforeErrorHook = (error) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
;(error as any).source = (error as any).options.context.stack.split('\n')
error.message += ` (request to ${request?.options.url.href})`
if (error instanceof HTTPError) {
try {
const details = JSON.parse((error.response?.body as string) || '{}')
// eslint-disable-next-line @typescript-eslint/no-explicit-any
;(error as any).statusCode = details.status
} catch {
return error
}
}
return error
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@
}
]
},
"exclude": ["node_modules", "src/__tests__/*", "test-d"]
"exclude": ["node_modules", "src/__tests__/*", "test-d", "dist"]
}

0 comments on commit 4ff2861

Please sign in to comment.