Skip to content

Commit

Permalink
tweak: optimize show error
Browse files Browse the repository at this point in the history
  • Loading branch information
bitxeno committed Jul 8, 2023
1 parent 779f2e4 commit 1ab3bd9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 31 deletions.
20 changes: 10 additions & 10 deletions router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func Create(app *fiber.App, f fs.FS) {

devices, err := manager.GetDevices()
if err != nil {
return c.Status(500).JSON(apiError(err.Error()))
return c.Status(http.StatusOK).JSON(apiError(err.Error()))
} else {
return c.Status(http.StatusOK).JSON(apiSuccess(devices))
}
Expand Down Expand Up @@ -135,7 +135,7 @@ func Create(app *fiber.App, f fs.FS) {

devices, err := manager.GetDevices()
if err != nil {
return c.Status(500).JSON(apiError(err.Error()))
return c.Status(http.StatusOK).JSON(apiError(err.Error()))
} else {
return c.Status(http.StatusOK).JSON(apiSuccess(devices))
}
Expand All @@ -150,7 +150,7 @@ func Create(app *fiber.App, f fs.FS) {
api.Post("/pair", func(c *fiber.Ctx) error {
devices, err := manager.GetDevices()
if err != nil {
return c.Status(500).JSON(apiError(err.Error()))
return c.Status(http.StatusOK).JSON(apiError(err.Error()))
} else {
return c.Status(http.StatusOK).JSON(apiSuccess(devices))
}
Expand All @@ -164,7 +164,7 @@ func Create(app *fiber.App, f fs.FS) {
for _, file := range files {
saveDir := filepath.Join(cfg.Server.WorkDir, "tmp")
if err := os.MkdirAll(saveDir, os.ModePerm); err != nil {
return c.Status(500).JSON(apiError("failed to create directory :" + saveDir))
return c.Status(http.StatusOK).JSON(apiError("failed to create directory :" + saveDir))
}

name := service.GetValidName(utils.FileNameWithoutExt(file.Filename))
Expand All @@ -173,7 +173,7 @@ func Create(app *fiber.App, f fs.FS) {

// Upload the file to specific dst.
if err := c.SaveFile(file, dst); err != nil {
return c.Status(500).JSON(apiError(err.Error()))
return c.Status(http.StatusOK).JSON(apiError(err.Error()))
}

ipaFile := model.IpaFile{
Expand All @@ -183,14 +183,14 @@ func Create(app *fiber.App, f fs.FS) {

info, err := ipa.ParseFile(dst)
if err != nil {
return c.Status(500).JSON(apiError(err.Error()))
return c.Status(http.StatusOK).JSON(apiError(err.Error()))
}

ipaFile.Name = info.Name()
ipaFile.BundleIdentifier = info.Identifier()
ipaFile.Version = info.Version()
if err := os.MkdirAll(saveDir, os.ModePerm); err != nil {
return c.Status(500).JSON(apiError("failed to create directory :" + saveDir))
return c.Status(http.StatusOK).JSON(apiError("failed to create directory :" + saveDir))
}

// 保存icon
Expand All @@ -216,7 +216,7 @@ func Create(app *fiber.App, f fs.FS) {
api.Get("/apps", func(c *fiber.Ctx) error {
apps, err := service.GetAppList()
if err != nil {
return c.Status(500).JSON(apiError(err.Error()))
return c.Status(http.StatusOK).JSON(apiError(err.Error()))
} else {
return c.Status(http.StatusOK).JSON(apiSuccess(apps))
}
Expand All @@ -230,12 +230,12 @@ func Create(app *fiber.App, f fs.FS) {
api.Post("/apps", func(c *fiber.Ctx) error {
var installApp model.InstalledApp
if err := c.BodyParser(&installApp); err != nil {
return c.Status(500).JSON(apiError(err.Error()))
return c.Status(http.StatusOK).JSON(apiError(err.Error()))
}

ipa, err := service.SaveApp(installApp)
if err != nil {
return c.Status(500).JSON(apiError(err.Error()))
return c.Status(http.StatusOK).JSON(apiError(err.Error()))
} else {
return c.Status(http.StatusOK).JSON(apiSuccess(ipa))
}
Expand Down
36 changes: 18 additions & 18 deletions view/src/page/install/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -191,25 +191,25 @@ export default {
formData.append("files", file);
}
_this.log.output += "IPA uploading...\n";
api.upload(formData).then((res) => {
let ipa = res.data[0];
_this.ipa = ipa;
api
.upload(formData)
.then((res) => {
let ipa = res.data[0];
_this.ipa = ipa;
// 为每个appleid创建对应的工作目录,用于存储AltServer生成的签名证书
let dirName = _this.form.account
.toLowerCase()
.replace(/[^0-9a-zA-Z]+/gi, "");
let workdir = `./AltServer/${dirName}`;
_this.websocketsend(
`mkdir -p ${workdir} && cd ${workdir} && AltServer -u ${_this.device.udid} -a '${_this.form.account}' -p '${_this.form.password}' '${ipa.path}'`
);
});
},
onCancel() {
this.$message({
message: "cancel!",
type: "warning",
});
// 为每个appleid创建对应的工作目录,用于存储AltServer生成的签名证书
let dirName = _this.form.account
.toLowerCase()
.replace(/[^0-9a-zA-Z]+/gi, "");
let workdir = `./AltServer/${dirName}`;
_this.websocketsend(
`mkdir -p ${workdir} && cd ${workdir} && AltServer -u ${_this.device.udid} -a '${_this.form.account}' -p '${_this.form.password}' '${ipa.path}'`
);
})
.catch((error) => {
console.log(error);
_this.log.output += error;
});
},
reset() {
document.getElementById("form").reset();
Expand Down
6 changes: 3 additions & 3 deletions view/src/utils/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ service.interceptors.response.use(

// if the custom code is not 200, it is judged as an error.
if (res.code !== 200) {
const msg = `${res.msg} (code: ${res.code})` || `Error (code: ${res.code})`;
toast.error(msg, {autoClose: 5000});
const msg = res.msg ? `${res.msg} (code: ${res.code})` : `Error (code: ${res.code})`;
toast.error(msg, { autoClose: 5000 });
return Promise.reject(new Error(msg));
} else {
return res;
}
},
(error) => {
console.log("err" + error); // for debug
toast.error(error.message, {autoClose: 5000});
toast.error(error.message, { autoClose: 5000 });
return Promise.reject(error);
}
);
Expand Down

0 comments on commit 1ab3bd9

Please sign in to comment.