JlSonic/JlSonic/errors.jl

40 lines
1.4 KiB
Julia

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)
upgrade_server(m) =
error(30, "$m. 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)
unauthorized() =
error(50, "User is not authorized for the given operation.", 401)
unauthorized(m) =
error(50, "User is not authorized for the given operation ($m).", 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)
(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 Dict(:status => error_code,
:body => doc_str)
end