JlSonic/JlSonic/errors.jl

35 lines
1.2 KiB
Julia
Raw Normal View History

2019-05-17 20:22:01 +02:00
import Mux
# https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
error() = error(0, "A generic error.", 500)
missing_parameter() = error(10, "Required parameter is missing.", 400)
missing_parameter(n) = error(10, "Required parameter ($n) is missing.", 400)
upgrade_client() =
error(20, "Incompatible Subsonic REST protocol version. Client must upgrade.", 400)
upgrade_server() =
error(30, "Incompatible Subsonic REST protocol version. Server must upgrade.", 501)
auth_failed() =
error(40, "Wrong username or password.", 401)
ldap_unsupported() =
error(41, "Token authentication not supported for LDAP users.", 501)
unuthorized() =
error(50, "User is not authorized for the given operation.", 401)
not_found() =
error(70, "The requested data was not found.", 404)
not_found(n) =
error(70, "The requested data ($n) was not found.", 404)
# FIXME: to use the status, we need to take the request dict
function error(code, message, error_code)
Mux.status(error_code)
(xdoc, xroot) = subsonic(version = "1.1.0", status = "failed")
er = new_child(xroot, "error")
set_attributes(er, [("code", string(code)),
("message", string(message))])
doc_str = string(xdoc)
free(xdoc)
return doc_str
end