1
0
Fork 0
mirror of https://github.com/VueTorrent/VueTorrent.git synced 2025-02-22 10:19:11 +03:00

perf(Login): Improve error message ()

This commit is contained in:
Rémi Marseault 2024-09-18 08:09:57 -05:00 committed by GitHub
parent 73c7daff88
commit 7c3fb619f9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 36 additions and 15 deletions

View file

@ -26,13 +26,20 @@ const rules = {
const login = async () => {
if (!rulesOk.value) return
await appStore.login(loginForm.username, loginForm.password)
const response = await appStore.login(loginForm.username, loginForm.password)
if (appStore.isAuthenticated) {
toast.success(t('login.success'))
redirectOnSuccess()
} else {
toast.error(t('login.error'))
let message = t('login.error')
if (response.status !== 200) {
message += `
Error code: ${response.status} (${response.data})`
}
toast.error(message)
}
}

View file

@ -17,6 +17,7 @@ import {
import { NetworkInterface } from '@/types/qbit/models/AppPreferences'
import { AddTorrentPayload, AppPreferencesPayload, CreateFeedPayload, GetTorrentPayload, LoginPayload } from '@/types/qbit/payloads'
import { MaindataResponse, SearchResultsResponse, TorrentPeersResponse } from '@/types/qbit/responses'
import { AxiosResponse } from 'axios'
export default interface IProvider {
/// AppController ///
@ -58,7 +59,7 @@ export default interface IProvider {
/**
* Login to the application
*/
login(params: LoginPayload): Promise<string>
login(params: LoginPayload): Promise<AxiosResponse<string, string>>
/**
* Logout from the application

View file

@ -1,4 +1,11 @@
import { ConnectionStatus, FilePriority, LogType, PieceState, TorrentOperatingMode, TorrentState } from '@/constants/qbit'
import {
ConnectionStatus,
FilePriority,
LogType,
PieceState,
TorrentOperatingMode,
TorrentState
} from '@/constants/qbit'
import { ContentLayout, ProxyType, ResumeDataStorageType, StopCondition } from '@/constants/qbit/AppPreferences'
import type {
ApplicationVersion,
@ -21,6 +28,7 @@ import type { AddTorrentPayload, GetTorrentPayload } from '@/types/qbit/payloads
import { AppPreferencesPayload, CreateFeedPayload, LoginPayload } from '@/types/qbit/payloads'
import type { MaindataResponse, SearchResultsResponse, TorrentPeersResponse } from '@/types/qbit/responses'
import { faker } from '@faker-js/faker/locale/en'
import { AxiosResponse } from 'axios'
import IProvider from './IProvider'
export default class MockProvider implements IProvider {
@ -46,7 +54,8 @@ export default class MockProvider implements IProvider {
.fill('')
.map((_, i) => (i + 1).toString(16).padStart(40, '0'))
private constructor() {}
private constructor() {
}
static getInstance(): MockProvider {
if (!MockProvider.instance) {
@ -86,7 +95,7 @@ export default class MockProvider implements IProvider {
infohash_v1: hash,
infohash_v2: '',
last_activity: last_activity.getTime() / 1000,
magnet_uri: `magnet:?xt=urn:btih:${hash}&dn=${name}&tr=${tracker}`,
magnet_uri: `magnet:?xt=urn:btih:${ hash }&dn=${ name }&tr=${ tracker }`,
max_inactive_seeding_time: -1,
max_ratio: -1,
max_seeding_time: -1,
@ -392,8 +401,14 @@ export default class MockProvider implements IProvider {
/// AuthController ///
async login(_: LoginPayload): Promise<string> {
return this.generateResponse({ result: 'Ok.' })
async login(_: LoginPayload): Promise<AxiosResponse<string, string>> {
return this.generateResponse({
result: {
data: 'Ok.',
status: 200,
statusText: 'OK',
} as AxiosResponse<string, string>
})
}
async logout(): Promise<void> {

View file

@ -19,7 +19,7 @@ import { NetworkInterface } from '@/types/qbit/models/AppPreferences'
import type { AddTorrentPayload, AppPreferencesPayload, CreateFeedPayload, GetTorrentPayload, LoginPayload } from '@/types/qbit/payloads'
import type { MaindataResponse, SearchResultsResponse, TorrentPeersResponse } from '@/types/qbit/responses'
import type { AxiosInstance } from 'axios'
import axios from 'axios'
import axios, { AxiosResponse } from 'axios'
import type IProvider from './IProvider'
type Parameters = Record<string, any>
@ -113,12 +113,9 @@ export default class QBitProvider implements IProvider {
/// AuthController ///
async login(params: LoginPayload): Promise<string> {
async login(params: LoginPayload): Promise<AxiosResponse<string, string>> {
const payload = new URLSearchParams(params as Parameters)
return this.axios.post('/auth/login', payload, { validateStatus: (status: number) => status === 200 || status === 403 }).then(
res => res.data,
err => console.log(err)
)
return this.axios.post('/auth/login', payload, { validateStatus: () => true })
}
async logout(): Promise<void> {

View file

@ -26,7 +26,8 @@ export const useAppStore = defineStore('app', () => {
async function login(username: string, password: string) {
const response = await qbit.login({ username, password })
await setAuthStatus(response === 'Ok.')
await setAuthStatus(response.data === 'Ok.')
return response
}
async function logout() {