Skip to content

Commit

Permalink
chore: lint and removing unnecesary else
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarosabu committed Oct 16, 2024
1 parent 90ccd57 commit 2b48927
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
10 changes: 4 additions & 6 deletions src/commands/login/actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ const emailRegex = /^[^\s@]+@[^\s@][^\s.@]*\.[^\s@]+$/
const handlers = [
http.get('https://api.storyblok.com/v1/users/me', async ({ request }) => {
const token = request.headers.get('Authorization')
if (token === 'valid-token') { return HttpResponse.json({ data: 'user data' }) }
if (token === 'valid-token') {
return HttpResponse.json({ data: 'user data' })
}
return new HttpResponse('Unauthorized', { status: 401 })
}),
http.post('https://api.storyblok.com/v1/users/login', async ({ request }) => {
Expand All @@ -31,14 +33,10 @@ const handlers = [

const server = setupServer(...handlers)

// Start server before all tests
beforeAll(() => server.listen({ onUnhandledRequest: 'error' }))

// Close server after all tests
afterAll(() => server.close())

// Reset handlers after each test `important for test isolation`
afterEach(() => server.resetHandlers())
afterAll(() => server.close())

describe('login actions', () => {
describe('loginWithToken', () => {
Expand Down
4 changes: 1 addition & 3 deletions src/utils/error/api-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ export function handleAPIError(action: keyof typeof API_ACTIONS, error: Error):
else if (error.message.includes('NetworkError') || error.message.includes('Failed to fetch')) {
throw new APIError('network_error', action, error)
}
else {
throw new APIError('generic', action, error)
}
throw new APIError('generic', action, error)
}

export class APIError extends Error {
Expand Down

0 comments on commit 2b48927

Please sign in to comment.