mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 08:49:13 +00:00
fix(user): change username (#1502)
* fix(user): change username * fix(user): api client error improvements * fix(user): api client error improvements
This commit is contained in:
parent
da53230077
commit
5857945e71
3 changed files with 18 additions and 14 deletions
|
@ -134,12 +134,14 @@ func (s *service) UpdateUser(ctx context.Context, req domain.UpdateUserRequest)
|
|||
return errors.Errorf("invalid login: %s", req.UsernameCurrent)
|
||||
}
|
||||
|
||||
hashed, err := s.CreateHash(req.PasswordNew)
|
||||
if err != nil {
|
||||
return errors.New("failed to hash password")
|
||||
}
|
||||
if req.PasswordNew != "" {
|
||||
hashed, err := s.CreateHash(req.PasswordNew)
|
||||
if err != nil {
|
||||
return errors.New("failed to hash password")
|
||||
}
|
||||
|
||||
req.PasswordNewHash = hashed
|
||||
req.PasswordNewHash = hashed
|
||||
}
|
||||
|
||||
if err := s.userSvc.Update(ctx, req); err != nil {
|
||||
s.log.Error().Err(err).Msgf("could not change password for user: %s", req.UsernameCurrent)
|
||||
|
|
|
@ -81,23 +81,22 @@ export async function HttpClient<T = unknown>(
|
|||
|
||||
const response = await window.fetch(`${baseUrl()}${endpoint}`, init);
|
||||
|
||||
const isJson = response.headers.get("Content-Type")?.includes("application/json");
|
||||
const json = isJson ? await response.json() : null;
|
||||
|
||||
switch (response.status) {
|
||||
case 204: {
|
||||
// 204 contains no data, but indicates success
|
||||
return Promise.resolve<T>({} as T);
|
||||
}
|
||||
case 401: {
|
||||
return Promise.reject(response);
|
||||
// return Promise.reject(new Error(`[401] Unauthorized: "${endpoint}"`));
|
||||
return Promise.reject<T>(json as T);
|
||||
}
|
||||
case 403: {
|
||||
return Promise.reject(response);
|
||||
return Promise.reject<T>(json as T);
|
||||
}
|
||||
case 404: {
|
||||
const isJson = response.headers.get("Content-Type")?.includes("application/json");
|
||||
const json = isJson ? await response.json() : null;
|
||||
return Promise.reject<T>(json as T);
|
||||
// return Promise.reject(new Error(`[404] Not Found: "${endpoint}"`));
|
||||
}
|
||||
case 500: {
|
||||
const health = await window.fetch(`${baseUrl()}api/healthz/liveness`);
|
||||
|
@ -116,9 +115,6 @@ export async function HttpClient<T = unknown>(
|
|||
break;
|
||||
}
|
||||
|
||||
const isJson = response.headers.get("Content-Type")?.includes("application/json");
|
||||
const json = isJson ? await response.json() : null;
|
||||
|
||||
// Resolve on success
|
||||
if (response.status >= 200 && response.status < 300) {
|
||||
if (isJson) {
|
||||
|
|
|
@ -52,6 +52,12 @@ export const queryClient = new QueryClient({
|
|||
},
|
||||
mutations: {
|
||||
onError: (error) => {
|
||||
console.log("mutation error: ", error)
|
||||
|
||||
if (error instanceof Response) {
|
||||
return
|
||||
}
|
||||
|
||||
// Use a format string to convert the error object to a proper string without much hassle.
|
||||
const message = (
|
||||
typeof (error) === "object" && typeof ((error as Error).message) ?
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue