rest - What should my JSON response contain when I have an HTTPException? -
i let users register application in following code:
[system.web.http.httppost] [system.web.http.allowanonymous] //[validateantiforgerytoken] //public httpresponsemessage register(registermodel model, string returnurl) public userprofiledto register(registermodel model) { if (modelstate.isvalid) { if (websecurity.userexists(model.username)) { throw new httpresponseexception(httpstatuscode.conflict); } else { // attempt register user try { websecurity.createuserandaccount(model.username, model.password); websecurity.login(model.username, model.password); initiatedatabasefornewuser(model.username); formsauthentication.setauthcookie(model.username, createpersistentcookie: false); var responsemessage = new httpresponsemessage(httpstatuscode.redirect); responsemessage.headers.location = new uri("http://www.google.com"); return _service.getuserprofile(websecurity.currentuserid); } catch (membershipcreateuserexception e) { throw new httpresponseexception(httpstatuscode.notfound); } } } // if got far, failed throw new httpresponseexception(httpstatuscode.notfound); }
my question(s): if hit 1 of exceptions, i'd tell user "hey, username exists!" or "yikes, happened. we're looking it." etc. clientside, how should handling this? check status in header , send view accordingly?
does mean each possible error should use different status code? seems wrong... leads me asking - should sending kind of status-related data client? if so, should return type (in case, userprofiledto) contain field "status" can populate see fit in controller?
sorry asked bunch there... trying figure out how right.
the reasonphrase exists purpose of providing readable description of why error occurred. if simple textual description not sufficient convey problem end user there emerging standard ways of describing problem user.
application/api-problem+json
http://tools.ietf.org/html/draft-nottingham-http-problem-03 application/api-problem+xml
application/vnd.error+json
https://github.com/blongden/vnd.error application/vnd.error+xml
Comments
Post a Comment