Skip to content

Commit

Permalink
Export ThriftRequestError and fix tests. (#13)
Browse files Browse the repository at this point in the history
In #9 we changed thrift-client to return an instance of ThriftRequestError when the client gets an HTTP error. This commit exports the ThriftRequestError class and fixes some test assertions in light of those changes.

I feel good about it!
  • Loading branch information
markdoliner-doma authored Jul 6, 2022
1 parent 38fe76c commit de2dcf2
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
1 change: 1 addition & 0 deletions packages/thrift-client/src/main/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './connections'
export * from './errors'
export * from './types'
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
IThriftRequest,
NextFunction,
RequestOptions,
ThriftRequestError,
} from '@statestitle/thrift-client'
import { ThriftClientTTwitterFilter, TTwitter } from '@statestitle/thrift-client-ttwitter-filter'
import * as thrift from '@statestitle/thrift-server-core'
Expand Down Expand Up @@ -136,8 +137,12 @@ describe('HttpConnection', () => {
() => {
throw new Error('Should reject with status 500')
},
(err: Response) => {
expect(err.status).to.equal(500)
(err: ThriftRequestError) => {
expect(err).to.be.an.error(
ThriftRequestError,
'Thrift request failed: HTTP 500 Internal Server Error: NOPE'
)
expect(err.response?.status).to.equal(500)
}
)
})
Expand All @@ -155,8 +160,12 @@ describe('HttpConnection', () => {
() => {
throw new Error('Should reject with status 400')
},
(err: Response) => {
expect(err.status).to.equal(400)
(err: ThriftRequestError) => {
expect(err).to.be.an.error(
ThriftRequestError,
'Thrift request failed: HTTP 400 Bad Request: NOPE'
)
expect(err.response?.status).to.equal(400)
}
)
})
Expand Down
33 changes: 25 additions & 8 deletions packages/thrift-integration/src/client/connections/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
IThriftRequest,
NextFunction,
RequestOptions,
ThriftRequestError,
} from '@statestitle/thrift-client'
import { Int64, readThriftMethod } from '@statestitle/thrift-server-core'

Expand Down Expand Up @@ -256,8 +257,12 @@ describe('createHttpClient', () => {
() => {
throw new Error('Should reject with status 500')
},
(err: Response) => {
expect(err.status).to.equal(500)
(err: ThriftRequestError) => {
expect(err).to.be.an.error(
ThriftRequestError,
'Thrift request failed: HTTP 500 Internal Server Error: NOPE'
)
expect(err.response?.status).to.equal(500)
}
)
})
Expand All @@ -273,8 +278,12 @@ describe('createHttpClient', () => {
() => {
throw new Error('Should reject with status 400')
},
(err: Response) => {
expect(err.status).to.equal(400)
(err: ThriftRequestError) => {
expect(err).to.be.an.error(
ThriftRequestError,
'Thrift request failed: HTTP 400 Bad Request: NOPE'
)
expect(err.response?.status).to.equal(400)
}
)
})
Expand Down Expand Up @@ -461,8 +470,12 @@ describe('createHttpClient', () => {
() => {
throw new Error('Should reject with status 500')
},
(err: Response) => {
expect(err.status).to.equal(500)
(err: ThriftRequestError) => {
expect(err).to.be.an.error(
ThriftRequestError,
'Thrift request failed: HTTP 500 Internal Server Error: NOPE'
)
expect(err.response?.status).to.equal(500)
}
)
})
Expand All @@ -478,8 +491,12 @@ describe('createHttpClient', () => {
() => {
throw new Error('Should reject with status 400')
},
(err: Response) => {
expect(err.status).to.equal(400)
(err: ThriftRequestError) => {
expect(err).to.be.an.error(
ThriftRequestError,
'Thrift request failed: HTTP 400 Bad Request: NOPE'
)
expect(err.response?.status).to.equal(400)
}
)
})
Expand Down

0 comments on commit de2dcf2

Please sign in to comment.