Skip to content

Commit 1e32aa8

Browse files
committed
Fixing error handling
1 parent 37b261b commit 1e32aa8

File tree

4 files changed

+37
-7
lines changed

4 files changed

+37
-7
lines changed

__tests__/main.test.ts

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,43 @@ describe('action', () => {
149149
}
150150
})
151151

152-
fetchMock.mockResponseOnce('Something went wrong', {
153-
status: 400,
154-
statusText: 'Bad Request'
152+
fetchMock.mockResponseOnce(
153+
JSON.stringify({ message: 'Something went wrong' }),
154+
{
155+
status: 400,
156+
statusText: 'Bad Request'
157+
}
158+
)
159+
await main.run()
160+
expect(setFailedMock).toHaveBeenCalledWith(
161+
'HTTP Error: 400, Bad Request, {"message":"Something went wrong"}'
162+
)
163+
})
164+
it('should handle a 500 error', async () => {
165+
getInputMock.mockImplementation(name => {
166+
switch (name) {
167+
case 'test':
168+
return 'false'
169+
case 'spec':
170+
return path.join(__dirname, 'data', 'testspec.lua')
171+
case 'download-url':
172+
return 'https://example.com/test.zip'
173+
case 'api':
174+
return 'https://example.com/'
175+
case 'token':
176+
return 'token'
177+
default:
178+
return ''
179+
}
180+
})
181+
182+
fetchMock.mockResponseOnce('', {
183+
status: 500,
184+
statusText: 'Internal Server Error'
155185
})
156186
await main.run()
157187
expect(setFailedMock).toHaveBeenCalledWith(
158-
'HTTP Error: Something went wrong'
188+
'HTTP Error: 500, Internal Server Error, '
159189
)
160190
})
161191
it('Should create a new plugin if not found', async () => {

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/extensionstore.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ async function request(
174174
})
175175
if (!response.ok) {
176176
throw new Error(
177-
`HTTP Error: ${(response.status, response.statusText, await response.text())}`
177+
`HTTP Error: ${response.status}, ${response.statusText}, ${await response.text()}`
178178
)
179179
}
180180
return await response.json()

0 commit comments

Comments
 (0)