comparison mod_rest/mod_rest.lua @ 3843:c065b7670c89

mod_rest: Return a friendly message for parse errors And details in the error context that should be included thanks to previous commit.
author Kim Alvefur <zash@zash.se>
date Wed, 15 Jan 2020 21:41:42 +0100
parents 501c7edc8c37
children 29c39876c4af
comparison
equal deleted inserted replaced
3842:501c7edc8c37 3843:c065b7670c89
71 return 401; 71 return 401;
72 end 72 end
73 local payload, err = parse(request.headers.content_type, request.body); 73 local payload, err = parse(request.headers.content_type, request.body);
74 if not payload then 74 if not payload then
75 -- parse fail 75 -- parse fail
76 return errors.new({ code = 400, text = err }); 76 return errors.new({ code = 400, text = "Failed to parse payload" }, { error = err, type = request.headers.content_type, data = request.body });
77 end 77 end
78 if payload.attr.xmlns then 78 if payload.attr.xmlns then
79 return errors.new({ code = 422, text = "'xmlns' attribute must be empty" }); 79 return errors.new({ code = 422, text = "'xmlns' attribute must be empty" });
80 elseif payload.name ~= "message" and payload.name ~= "presence" and payload.name ~= "iq" then 80 elseif payload.name ~= "message" and payload.name ~= "presence" and payload.name ~= "iq" then
81 return errors.new({ code = 422, text = "Invalid stanza, must be 'message', 'presence' or 'iq'." }); 81 return errors.new({ code = 422, text = "Invalid stanza, must be 'message', 'presence' or 'iq'." });