Software /
code /
prosody
Comparison
prosodyctl @ 2329:e497718194a3
prosodyctl: Nicer errors when addplugin command fails
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 07 Dec 2009 18:30:57 +0000 |
parent | 2277:c5d3905c98a6 |
child | 2410:ce912b648741 |
comparison
equal
deleted
inserted
replaced
2328:2804d81206d8 | 2329:e497718194a3 |
---|---|
460 | 460 |
461 show_message(error_messages[msg]) | 461 show_message(error_messages[msg]) |
462 return 1; | 462 return 1; |
463 end | 463 end |
464 | 464 |
465 local http_errors = { | |
466 [404] = "Plugin not found, did you type the address correctly?" | |
467 }; | |
468 | |
465 function commands.addplugin(arg) | 469 function commands.addplugin(arg) |
466 local url = arg[1]; | 470 local url = arg[1]; |
467 if url:match("^http://") then | 471 if url:match("^http://") then |
468 local http = require "socket.http"; | 472 local http = require "socket.http"; |
469 show_message("Fetching..."); | 473 show_message("Fetching..."); |
470 local code, err = http.request(url); | 474 local code, err = http.request(url); |
471 if not code then | 475 if not code or not tostring(err):match("^[23]") then |
472 show_message("Failed: "..err); | 476 show_message("Failed: "..(http_errors[err] or ("HTTP error "..err))); |
473 return 1; | 477 return 1; |
474 end | 478 end |
475 if url:match("%.lua$") then | 479 if url:match("%.lua$") then |
476 local ok, err = datamanager.store(url:match("/mod_([^/]+)$"), "*", "plugins", {code}); | 480 local ok, err = datamanager.store(url:match("/mod_([^/]+)$"), "*", "plugins", {code}); |
477 if not ok then | 481 if not ok then |