Skip to content

Commit d1b7b5f

Browse files
committed
remove stack hack
#211 (comment)
1 parent 7957443 commit d1b7b5f

File tree

3 files changed

+2
-26
lines changed

3 files changed

+2
-26
lines changed

src/ApiError.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ export class ApiError extends Error {
2121

2222
constructor(params: {
2323
cause?: HTTPError
24-
appendStack?: string
2524
body: TransloaditErrorResponseBody | undefined
2625
}) {
27-
const { cause, body = {}, appendStack } = params
26+
const { cause, body = {} } = params
2827

2928
const parts = ['API error']
3029
if (cause?.response.statusCode) parts.push(`(HTTP ${cause.response.statusCode})`)
@@ -35,19 +34,6 @@ export class ApiError extends Error {
3534
const message = parts.join(' ')
3635

3736
super(message)
38-
39-
// if we have a cause, use the stack trace from it instead
40-
if (cause != null && typeof cause.stack === 'string') {
41-
const indexOfMessageEnd = cause.stack.indexOf(cause.message) + cause.message.length
42-
const gotStacktrace = cause.stack.slice(indexOfMessageEnd)
43-
this.stack = `${message}${gotStacktrace}`
44-
}
45-
46-
// If we have an original stack, append it to the bottom, because `got`s stack traces are not very good
47-
if (this.stack != null && appendStack != null) {
48-
this.stack += `\n${appendStack.replace(/^([^\n]+\n)/, '')}`
49-
}
50-
5137
this.rawMessage = body.message
5238
this.assemblyId = body.assembly_id
5339
this.assemblySslUrl = body.assembly_ssl_url

src/Transloadit.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -732,10 +732,6 @@ export class Transloadit {
732732
responseType: 'json',
733733
}
734734

735-
// `got` stacktraces are very lacking, so we capture our own
736-
// https://github.com/sindresorhus/got/blob/main/documentation/async-stack-traces.md
737-
const stack = new Error().stack
738-
739735
try {
740736
const request = got[method]<T>(url, requestOpts)
741737
const { body } = await request
@@ -766,7 +762,6 @@ export class Transloadit {
766762
) {
767763
throw new ApiError({
768764
cause: err,
769-
appendStack: stack,
770765
body: body as TransloaditErrorResponseBody,
771766
}) // todo don't assert type
772767
}

test/unit/mock-http.test.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,21 +133,16 @@ describe('Mocked API tests', () => {
133133
),
134134
expect.stringMatching(` at .+`),
135135
expect.stringMatching(` at .+`),
136-
expect.stringMatching(
137-
` at Transloadit\\._remoteJson \\(.+\\/src\\/Transloadit\\.ts:\\d+:\\d+\\)`
138-
),
139136
expect.stringMatching(
140137
` at createAssemblyAndUpload \\(.+\\/src\\/Transloadit\\.ts:\\d+:\\d+\\)`
141138
),
142-
expect.stringMatching(` at .+\\/src\\/Transloadit\\.ts:\\d+:\\d+`),
143-
expect.stringMatching(` at .+`),
144139
expect.stringMatching(` at .+\\/test\\/unit\\/mock-http\\.test\\.ts:\\d+:\\d+`),
145140
expect.stringMatching(` at .+`),
146141
expect.stringMatching(` at .+`),
147142
expect.stringMatching(` at .+`),
148143
expect.stringMatching(` at .+`),
149144
expect.stringMatching(` at .+`),
150-
expect.stringMatching(` name: 'ApiError',`),
145+
expect.stringMatching(` at .+`),
151146
expect.stringMatching(` rawMessage: 'Invalid file metadata',`),
152147
expect.stringMatching(` assemblyId: '123',`),
153148
expect.stringMatching(

0 commit comments

Comments
 (0)