Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/npm_and_yarn/lodash-4.17.21
Browse files Browse the repository at this point in the history
  • Loading branch information
Nevon authored Jan 28, 2022
2 parents 8ff33b8 + 8bac919 commit 751b71b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/api/middleware/errorMiddleware.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ describe('ErrorMiddleware', () => {
).rejects.toHaveProperty('message', `${middlewareParams.clientId} - ${message}`)
})

it('raises an error with a message in case of client-side errors', async () => {
const message = 'error message'
const response = createResponse(message)

await expect(
executedMiddleware.response(() => Promise.reject(response), undefined),
).rejects.toHaveProperty(
'message',
`${middlewareParams.clientId} - Error, status 500: ${message}`,
)
})

it('raise an error with a default message if the error payload is empty', async () => {
const response = createResponse('')

Expand Down
5 changes: 4 additions & 1 deletion src/api/middleware/errorMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ class ResponseError extends Error {
url: string

constructor(clientName: string, response: ConfluenceResponse) {
super(`${clientName} - ${response.data().message || `Error, status ${response.status()}`}`)
super(
`${clientName} - ${response.data().message ||
`Error, status ${response.status()}${response.data() ? `: ${response.data()}` : ''}`}`,
)

const request = response.request()
this.name = this.constructor.name
Expand Down

0 comments on commit 751b71b

Please sign in to comment.