chore(error): improve error handling to include message from cause of error (#307)
* Refresh yarn.lock and node_modules to fix yarn test --coverage - based on https://github.com/vitest-dev/vitest/issues/4668#issuecomment-1840998029 * HttpError message included in the Error message
This commit is contained in:
+6
-1
@@ -38372,7 +38372,12 @@ const registerNewVersionForTheSpeckleAutomateFunction = async ({ speckleAutomate
|
||||
throw parsedResult.error;
|
||||
}
|
||||
catch (err) {
|
||||
throw Error('Failed to register new function version to the automate server', {
|
||||
if (err instanceof Error) {
|
||||
throw Error(`Failed to register new function version to the automate server. ${err.message}`, {
|
||||
cause: err
|
||||
});
|
||||
}
|
||||
throw Error(`Failed to register new function version to the automate server. ${err}`, {
|
||||
cause: err
|
||||
});
|
||||
}
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
+14
-3
@@ -173,9 +173,20 @@ const registerNewVersionForTheSpeckleAutomateFunction = async (
|
||||
if (parsedResult.success) return parsedResult.data
|
||||
throw parsedResult.error
|
||||
} catch (err) {
|
||||
throw Error('Failed to register new function version to the automate server', {
|
||||
cause: err
|
||||
})
|
||||
if (err instanceof Error) {
|
||||
throw Error(
|
||||
`Failed to register new function version to the automate server. ${err.message}`,
|
||||
{
|
||||
cause: err
|
||||
}
|
||||
)
|
||||
}
|
||||
throw Error(
|
||||
`Failed to register new function version to the automate server. ${err}`,
|
||||
{
|
||||
cause: err
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+78
-3
@@ -20,6 +20,49 @@ describe('Register new version', () => {
|
||||
let tmpDir: string
|
||||
let countHappyPath = 0
|
||||
let count500Errors = 0
|
||||
let count422Errors = 0
|
||||
|
||||
const error422 = {
|
||||
type: 'H3Error',
|
||||
message: 'Body parsing failed',
|
||||
stack: `Error: Body parsing failed
|
||||
at createError...`,
|
||||
statusCode: 422,
|
||||
fatal: false,
|
||||
unhandled: false,
|
||||
statusMessage: 'Body parsing failed',
|
||||
data: {
|
||||
type: 'ZodError',
|
||||
message:
|
||||
'[\n {\n "code": "custom",\n "message": "Invalid JSON schema: strict mode: unknown keyword: \\"IAmInvalid\\"",\n "path": [\n "inputSchema"\n ]\n }\n]',
|
||||
stack: {
|
||||
ZodError: [
|
||||
{
|
||||
code: 'custom',
|
||||
message: 'Invalid JSON schema: strict mode: unknown keyword: "IAmInvalid"',
|
||||
path: ['inputSchema']
|
||||
}
|
||||
]
|
||||
},
|
||||
aggregateErrors: [
|
||||
{
|
||||
type: 'Object',
|
||||
message: 'Invalid JSON schema: strict mode: unknown keyword: "IAmInvalid"',
|
||||
stack: {},
|
||||
code: 'custom',
|
||||
path: ['inputSchema']
|
||||
}
|
||||
],
|
||||
issues: [
|
||||
{
|
||||
code: 'custom',
|
||||
message: 'Invalid JSON schema: strict mode: unknown keyword: "IAmInvalid"',
|
||||
path: ['inputSchema']
|
||||
}
|
||||
],
|
||||
name: 'ZodError'
|
||||
}
|
||||
}
|
||||
|
||||
const server = setupServer(
|
||||
http.post(
|
||||
@@ -44,15 +87,29 @@ describe('Register new version', () => {
|
||||
return HttpResponse.error() // simulates a network error
|
||||
}
|
||||
),
|
||||
http.post(
|
||||
'http://myfakeautomate.speckle.internal/api/v1/functions/422_response/versions',
|
||||
async ({ request }) => {
|
||||
const parseResult = FunctionVersionRequestSchema.safeParse(await request.json())
|
||||
expect(parseResult.success).to.be.true
|
||||
count422Errors++
|
||||
return HttpResponse.json(error422, {
|
||||
status: 422
|
||||
})
|
||||
}
|
||||
),
|
||||
http.post(
|
||||
'http://myfakeautomate.speckle.internal/api/v1/functions/500_response/versions',
|
||||
async ({ request }) => {
|
||||
const parseResult = FunctionVersionRequestSchema.safeParse(await request.json())
|
||||
expect(parseResult.success).to.be.true
|
||||
count500Errors++
|
||||
return new HttpResponse(null, {
|
||||
status: 500
|
||||
})
|
||||
return HttpResponse.json(
|
||||
{},
|
||||
{
|
||||
status: 500
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
)
|
||||
@@ -123,6 +180,24 @@ describe('Register new version', () => {
|
||||
expect(count500Errors).to.toBeGreaterThan(1) // we expect the action to retry the request
|
||||
count500Errors = 0
|
||||
})
|
||||
it('handles 422 responses', async () => {
|
||||
writeFileSync(join(tmpDir, 'schema.json'), '{}')
|
||||
vi.stubEnv('INPUT_SPECKLE_FUNCTION_ID', '422_response')
|
||||
vi.stubEnv('INPUT_SPECKLE_TOKEN', '{token}')
|
||||
vi.stubEnv('INPUT_SPECKLE_FUNCTION_COMMAND', 'echo "hello automate"')
|
||||
vi.stubEnv('HOME', tmpDir) // the input schema file path is assumed to be relative to the home directory
|
||||
vi.stubEnv('INPUT_SPECKLE_FUNCTION_INPUT_SCHEMA_FILE_PATH', './schema.json')
|
||||
vi.stubEnv('INPUT_SPECKLE_FUNCTION_RELEASE_TAG', 'v1.0.0')
|
||||
vi.stubEnv('INPUT_SPECKLE_AUTOMATE_URL', 'http://myfakeautomate.speckle.internal')
|
||||
vi.stubEnv('GITHUB_SHA', 'commitSha')
|
||||
vi.stubEnv('GITHUB_REF_TYPE', 'commit')
|
||||
vi.stubEnv('GITHUB_REF_NAME', 'version')
|
||||
await expect(run()).rejects.toThrow(
|
||||
'Failed to register new function version to the automate server'
|
||||
)
|
||||
expect(count422Errors).to.eq(1) // we expect the action not to retry the request
|
||||
count422Errors = 0 // reset the count after the test
|
||||
})
|
||||
it('errors if the token is empty', async () => {
|
||||
writeFileSync(join(tmpDir, 'schema.json'), '{}')
|
||||
vi.stubEnv('INPUT_SPECKLE_FUNCTION_ID', 'fake_function_id')
|
||||
|
||||
Reference in New Issue
Block a user