Home > Error Handling > Api Error Message Design

Api Error Message Design


When browsing a website, decisions on what links will be clicked are made at run time. To get bonus points, localize the error messages. This is where things can get fuzzy. Sometimes you really have no way to map the action to a sensible RESTful structure. http://apexintsoft.com/error-handling/asp-net-mvc-ajax-error-message.php

For example, assume you try to set expiration and permissions (both of which are not permitted) on a shared link that is accessible to collaborators only, the error response would be: Why do Internet forums tend to prohibit responding to inactive threads? What is the role of conjectures in modern mathematics? A good error message also allows the developers to get their way out of the failed call. http://apigee.com/about/blog/technology/restful-api-design-what-about-errors

Api Error Handling Best Practices

Jun 30 '10 at 14:24 3 There seems to be a general understanding that you can do whatever you want with HTTP protocol and still be "RESTy", that's false. For instance, if the ‘folder_name_already_used’ error code is detected, the app can display a textbox with a “Rename” button that lets the client pick a different name for the folder. How to typedef the return type of a member function from a template class?

If the API is simple, URL encoding may suffice. So for security related information: usernames/passwords/API keys - I would err on the side of being vague rather than specific for anything that has sensitive information. Like Facebook, they provide a more granular error message but with a link that takes you to the documentation. Rest Api Error Handling Example You might consider using the Link header with an extended relation type such as ‘api-help’ to communicate the help URL (since the RFC does not define a standard relation type for

in order to do so, the rule of thumb is to keep the error messages to a minimum and only incorporate those error messages which are helpful. Rest Error Handling Example x Join 2000 Developers Learn how to build better software in the cloud. © Vinay Sahni current community blog chat Software Engineering Software Engineering Meta your communities Sign up or log Although there aren't any hard standards here, the popular convention is to accept a request header X-HTTP-Method-Override with a string value containing one of PUT, PATCH or DELETE. share|improve this answer answered Jul 16 '13 at 23:37 benjiman 1113 Since "Ooops!

Result filtering, sorting & searching It's best to keep the base resource URLs as lean as possible. Rest Api Response Best Practices For example, here is how Twitter handles error codes https://dev.twitter.com/docs/error-codes-responses share|improve this answer answered Oct 23 '13 at 5:39 Gokul 1,4641106 add a comment| up vote 2 down vote Don't forget Many popular JSON APIs use snake_case. and if the details aren't returned in the 403, a 404 "can" be used instead (doesn't sound like the best option to me, though). –Rich Apodaca Jun 3 '09 at 4:33

Rest Error Handling Example

Useful for debugging. http://programmers.stackexchange.com/questions/204387/best-practice-should-error-messages-be-handled-by-the-api-or-by-the-app if load balancers & reverse proxies can create custom error bodies), this should extend to 500 series status codes. Api Error Handling Best Practices Heavily informing the part of Starfighter's game that exposes an API. Rest Error Response Body Has anyone done anything like this before?

In the case of a successful API call they can proceed to the next call or whatever their intent was in the first place but in the case of latter they Browse other questions tagged web-services http rest or ask your own question. Go to Part 6: API Management → User Authentification, Provisioning, & Throttling The Advantages of using a Proxy for API Management Related Posts: Advanced API Patterns with RAML Dynamic CloudHub In environments with multiple clients this helps to keep things consistent and easier to maintain. Error Handling In Restful Web Services

Twilio Twilio does a great job aligning errors with HTTP status codes. API errors typically break down into 2 types: 400 series status codes for client issues & 500 series status codes for server issues. Option 2 seems like SOAP in rest clothes though... –Remus Rusanu Jun 3 '09 at 4:21 112 No, tunneling everything through a 200 is not restful at all. Not all of these are secure.

Like Facebook, they provide a more granular error message but with a link that takes you to the documentation. Rest Api Design Best Practices It is understandable that for the user it is easier to check the status code of 404 without any parsing work to do. Should I be using Design Patterns?

I've curated a short list of the ones that you definitely should be using: 200 OK - Response to a successful GET, PUT, PATCH or DELETE.

RFC 2616 defines the Status-Line syntax as shown below: Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF A great amount of applications are using Restful APIs that are based on the Let's look at some examples: GET /tickets?sort=-priority - Retrieves a list of tickets in descending order of priority GET /tickets?sort=-priority,created_at - Retrieves a list of tickets in descending order of priority. I've pulled some data from GitHub's API, which uses pretty print by default. Rest Api Validation Errors However, most developers don't have all 70 memorized.

data: ... # The data of the response, if any. The last thing you want is for poorly configured clients to send requests to an unencrypted endpoint, just to be silently redirected to the actual encrypted endpoint. In order to build a robust application, it needs to be able to gracefully handle errors as they arise. There are some cases where this status code is always returned, even if there was an error that occurred.

Even outside of globalization though, the UI should be the owner of all things that matter only to users and not to logic. –Jimmy Hoffa Jul 10 '13 at 20:53 add I am now adding some error cases, like for instance a client attempts to add a new resource but has exceeded his storage quota. For example an activate action could be mapped to a boolean activated field and updated via a PATCH to the resource. and What's Your P... 13386 The Digital Accelerator Interview: Somesh Nigam, I... 13361 Black Friday 2014: Customer Preparedness Checklist 13356 Build APIs in Node.js & Swagger 2.0 with Apige... 13346 Generating

Clients need to deal with errors by watching for network errors first (for instance, when the request did not even make it to the API server because the network was down Read more at http://…   Your JSON was not properly formed. Document... Don't do this!

This increases processing, adds latency, and creates an environment for the client to make mistakes. First, developers learn to write code through errors. I highly recommend you add a link in your description to more information, like Twilio does. Document the crap out of the error handling strategy you’ve decided on.

Secondly, in addition to when they're developing their applications, developers depend on well-designed errors at the critical times when they are troubleshooting and resolving issues after the applications they've built using The link destination, usually to a knowledge base, will provide more information about the error, often with suggested tips to resolve it. Sure, however, there isn't much to gain going down that route as code would still not be able to handle significant API changes without breaking.