Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
error-types
Advanced tools
When you implement a RESTful endpoint in Node.js you have to handle the error in response. This library give you a representation of common restful error. In particular they are mapped in an object through an index code as reported below in documentation. For every error you have thi data:
If you want use error-types you have to install it. There are two methods for that: In your package.json add the following item:
"error-types": "version"
then digit
npm install
Example:
"error-types": "*" for the latest version
"error-types": "1.0.0" for the version 1.0.0
OR
launch this command:
npm install error-types --save
After installed error-types library you can obtain an object that is a representation of one of the common restful error as reported below:
'use strict';
var errorTypes = require('error-types');
// I want Internal Server Error
console.log(errorTypes.INTERNAL_SERVER_ERROR);
/**
* Output:
* {
* code: 'INTERNAL_SERVER_ERROR',
* statusText: 'Internal Server Error',
* HTTPStatusCode: 500,
* description: 'The server encountered an unexpected condition which prevented it from fulfilling the request.'
* }
*/
Status code | Error name | Error type | Reference |
---|---|---|---|
400 | Bad Request | BAD_REQUEST | RFC7231, Section 6.5.1 |
The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications.
Status code | Error name | Error type | Reference |
---|---|---|---|
401 | Unauthorized | UNAUTHORIZED | RFC7235, Section 3.1 |
The request requires user authentication. The response MUST include a WWW-Authenticate header field containing a challenge applicable to the requested resource. The client MAY repeat the request with a suitable Authorization header field. If the request already included Authorization credentials, then the 401 response indicates that authorization has been refused for those credentials. If the 401 response contains the same challenge as the prior response, and the user agent has already attempted authentication at least once, then the user SHOULD be presented the entity that was given in the response, since that entity might include relevant diagnostic information.
Status code | Error name | Error type | Reference |
---|---|---|---|
403 | Forbidden | FORBIDDEN | RFC7231, Section 6.5.3 |
The server understood the request, but is refusing to fulfill it. Authorization will not help and the request SHOULD NOT be repeated. If the request method was not HEAD and the server wishes to make public why the request has not been fulfilled, it SHOULD describe the reason for the refusal in the entity. If the server does not wish to make this information available to the client, the status code 404 (Not Found) can be used instead.
Status code | Error name | Error type | Reference |
---|---|---|---|
404 | Not Found | NOT_FOUND | RFC7231, Section 6.5.4 |
The server has not found anything matching the Request-URI. No indication is given of whether the condition is temporary or permanent. The 410 (Gone) status code SHOULD be used if the server knows, through some internally configurable mechanism, that an old resource is permanently unavailable and has no forwarding address. This status code is commonly used when the server does not wish to reveal exactly why the request has been refused, or when no other response is applicable.
Status code | Error name | Error type | Reference |
---|---|---|---|
405 | Method Not Allowed | METHOD_NOT_ALLOWED | RFC7231, Section 6.5.5 |
The method specified in the Request-Line is not allowed for the resource identified by the Request-URI. The response MUST include an Allow header containing a list of valid methods for the requested resource.
Status code | Error name | Error type | Reference |
---|---|---|---|
406 | Not Acceptable | NOT_ACCEPTABLE | RFC7231, Section 6.5.6 |
The resource identified by the request is only capable of generating response entities which have content characteristics not acceptable according to the accept headers sent in the request.
Status code | Error name | Error type | Reference |
---|---|---|---|
407 | Proxy Authentication Required | PROXY_AUTHENTICATION_REQUIRED | RFC7235, Section 3.2 |
This code is similar to 401 (Unauthorized), but indicates that the client must first authenticate itself with the proxy. The proxy MUST return a Proxy-Authenticate header field containing a challenge applicable to the proxy for the requested resource. The client MAY repeat the request with a suitable Proxy-Authorization header field.
Status code | Error name | Error type | Reference |
---|---|---|---|
408 | Request Timeout | REQUEST_TIMEOUT | RFC7231, Section 6.5.7 |
The client did not produce a request within the time that the server was prepared to wait. The client MAY repeat the request without modifications at any later time.
Status code | Error name | Error type | Reference |
---|---|---|---|
409 | Conflict | CONFLICT | RFC7231, Section 6.5.8 |
The request could not be completed due to a conflict with the current state of the resource. This code is only allowed in situations where it is expected that the user might be able to resolve the conflict and resubmit the request. The response body SHOULD include enough information for the user to recognize the source of the conflict. Ideally, the response entity would include enough information for the user or user agent to fix the problem; however, that might not be possible and is not required.
Status code | Error name | Error type | Reference |
---|---|---|---|
410 | Gone | GONE | RFC7231, Section 6.5.9 |
The requested resource is no longer available at the server and no forwarding address is known. This condition is expected to be considered permanent. Clients with link editing capabilities SHOULD delete references to the Request-URI after user approval. If the server does not know, or has no facility to determine, whether or not the condition is permanent, the status code 404 (Not Found) SHOULD be used instead. This response is cacheable unless indicated otherwise.
Status code | Error name | Error type | Reference |
---|---|---|---|
411 | Length Required | LENGTH_REQUIRED | RFC7231, Section 6.5.10 |
The server refuses to accept the request without a defined Content- Length. The client MAY repeat the request if it adds a valid Content-Length header field containing the length of the message-body in the request message.
Status code | Error name | Error type | Reference |
---|---|---|---|
412 | Precondition Failed | PRECONDITION_FAILED | RFC7232, Section 4.2 |
The precondition given in one or more of the request-header fields evaluated to false when it was tested on the server. This response code allows the client to place preconditions on the current resource metainformation (header field data) and thus prevent the requested method from being applied to a resource other than the one intended.
Status code | Error name | Error type | Reference |
---|---|---|---|
413 | Request Entity Too Large | REQUEST_ENTITY_TOO_LARGE | RFC7231, Section 6.5.11 |
The server is refusing to process a request because the request entity is larger than the server is willing or able to process. The server MAY close the connection to prevent the client from continuing the request.
Status code | Error name | Error type | Reference |
---|---|---|---|
414 | Request-URI Too Long | REQUEST_URI_TOO_LONG | RFC7231, Section 6.5.12 |
The server is refusing to service the request because the Request-URI is longer than the server is willing to interpret. This rare condition is only likely to occur when a client has improperly converted a POST request to a GET request with long query information, when the client has descended into a URI black hole of redirection (e.g., a redirected URI prefix that points to a suffix of itself), or when the server is under attack by a client attempting to exploit security holes present in some servers using fixed-length buffers for reading or manipulating the Request-URI.
Status code | Error name | Error type | Reference |
---|---|---|---|
415 | Unsupported Media Type | UNSUPPORTED_MEDIA_TYPE | RFC7231, Section 6.5.13 |
The server is refusing to service the request because the entity of the request is in a format not supported by the requested resource for the requested method.
Status code | Error name | Error type | Reference |
---|---|---|---|
416 | Requested Range Not Satisfiable | REQUESTED_RANGE_NOT_SATISFIABLE | RFC7233, Section 4.4 |
A server SHOULD return a response with this status code if a request included a Range request-header field, and none of the range-specifier values in this field overlap the current extent of the selected resource, and the request did not include an If-Range request-header field. (For byte-ranges, this means that the first- byte-pos of all of the byte-range-spec values were greater than the current length of the selected resource.) When this status code is returned for a byte-range request, the response SHOULD include a Content-Range entity-header field specifying the current length of the selected resource. This response MUST NOT use the multipart/byteranges content-type.
Status code | Error name | Error type | Reference |
---|---|---|---|
417 | Expectation Failed | EXPECTATION_FAILED | RFC7231, Section 6.5.14 |
The expectation given in an Expect request-header field could not be met by this server, or, if the server is a proxy, the server has unambiguous evidence that the request could not be met by the next-hop server.
Status code | Error name | Error type | Reference |
---|---|---|---|
418 | I'm a teapot (RFC 2324) | I_AM_A_TEAPOT | No reference |
This code was defined in 1998 as one of the traditional IETF April Fools' jokes, in RFC 2324, Hyper Text Coffee Pot Control Protocol, and is not expected to be implemented by actual HTTP servers.
Status code | Error name | Error type | Reference |
---|---|---|---|
420 | Enhance Your Calm | ENHANCE_YOUR_CALM | No reference |
Returned by the API endpoint when the client is being rate limited. Likely a reference to this number's association with marijuana. Other services may wish to implement the 429 Too Many Requests response code instead.
Status code | Error name | Error type | Reference |
---|---|---|---|
422 | Unprocessable Entity | UNPROCESSABLE_ENTITY | RFC4918 |
The 422 - Unprocessable Entity status code means the server understands the content type of the request entity (hence a 415 - Unsupported Media Type status code is inappropriate), and the syntax of the request entity is correct (thus a 400 - Bad Request status code is inappropriate) but was unable to process the contained instructions. For example, this error condition may occur if an XML request body contains well-formed (i.e., syntactically correct), but semantically erroneous, XML instructions.
Status code | Error name | Error type | Reference |
---|---|---|---|
423 | Locked (WebDAV) | LOCKED | RFC4918 |
The 423 (Locked) status code means the source or destination resource of a method is locked. This response SHOULD contain an appropriate precondition or postcondition code, such as 'lock-token-submitted' or 'no-conflicting-lock'.
Status code | Error name | Error type | Reference |
---|---|---|---|
424 | Failed Dependency (WebDAV) | FAILED_DEPENDENCY | RFC4918 |
The 424 (Failed Dependency) status code means that the method could not be performed on the resource because the requested action depended on another action and that action failed.
Status code | Error name | Error type | Reference |
---|---|---|---|
425 | Reserved for WebDAV | RESERVED_FOR_WEBDAV | No reference |
Defined in drafts of WebDAV Advanced Collections Protocol, but not present in Web Distributed Authoring and Versioning (WebDAV) Ordered Collections Protocol.
Status code | Error name | Error type | Reference |
---|---|---|---|
426 | Upgrade Required | UPGRADE_REQUIRED | RFC7231, Section 6.5.15 |
Reliable, interoperable negotiation of Upgrade features requires an unambiguous failure signal. The 426 Upgrade Required status code allows a server to definitively state the precise protocol extensions a given resource must be served with.
Status code | Error name | Error type | Reference |
---|---|---|---|
428 | Precondition Required | PRECONDITION_REQUIRED | RFC6585 |
The origin server requires the request to be conditional. Intended to prevent the LOST UPDATE PROBLEM, where a client GETs a resource's state, modifies it, and PUTs it back to the server, when meanwhile a third party has modified the state on the server, leading to a conflict.
Status code | Error name | Error type | Reference |
---|---|---|---|
429 | Too Many Requests | TOO_MANY_REQUESTS | RFC6585 |
The 429 status code indicates that the user has sent too many requests in a given amount of time (rate limiting). The response representations SHOULD include details explaining the condition, and MAY include a Retry-After header indicating how long to wait before making a new request.
Status code | Error name | Error type | Reference |
---|---|---|---|
431 | Request Header Fields Too Large | REQUEST_HEADER_FIELDS_TOO_LARGE | RFC6585 |
The 431 status code indicates that the server is unwilling to process the request because its header fields are too large. The request MAY be resubmitted after reducing the size of the request header fields.
Status code | Error name | Error type | Reference |
---|---|---|---|
444 | No Response | NO_RESPONSE | No reference |
The server returns no information to the client and closes the connection (useful as a deterrent for malware).
Status code | Error name | Error type | Reference |
---|---|---|---|
449 | Retry With (Microsoft) | RETRY_WITH | No reference |
A Microsoft extension. The request should be retried after performing the appropriate action.
Status code | Error name | Error type | Reference |
---|---|---|---|
450 | Blocked by Windows Parental Controls (Microsoft) | BLOCKED_BY_WINDOWS_PARENTAL_CONTROLS | No reference |
A Microsoft extension. This error is given when Windows Parental Controls are turned on and are blocking access to the given webpage.
Status code | Error name | Error type | Reference |
---|---|---|---|
499 | Client Closed Request | CLIENT_CLOSED_REQUEST | No reference |
This code is introduced to log the case when the connection is closed by client while HTTP server is processing its request, making server unable to send the HTTP header back.
Status code | Error name | Error type | Reference |
---|---|---|---|
500 | Internal Server Error | INTERNAL_SERVER_ERROR | RFC7231, Section 6.6.1 |
The server encountered an unexpected condition which prevented it from fulfilling the request.
Status code | Error name | Error type | Reference |
---|---|---|---|
501 | Not Implemented | NOT_IMPLEMENTED | RFC7231, Section 6.6.2 |
The server does not support the functionality required to fulfill the request. This is the appropriate response when the server does not recognize the request method and is not capable of supporting it for any resource.
Status code | Error name | Error type | Reference |
---|---|---|---|
502 | Bad Gateway | BAD_GATEWAY | RFC7231, Section 6.6.3 |
The server, while acting as a gateway or proxy, received an invalid response from the upstream server it accessed in attempting to fulfill the request.
Status code | Error name | Error type | Reference |
---|---|---|---|
503 | Service Unavailable | SERVICE_UNAVAILABLE | RFC7231, Section 6.6.4 |
The server is currently unable to handle the request due to a temporary overloading or maintenance of the server. The implication is that this is a temporary condition which will be alleviated after some delay. If known, the length of the delay MAY be indicated in a Retry-After header. If no Retry-After is given, the client SHOULD handle the response as it would for a 500 response.
Status code | Error name | Error type | Reference |
---|---|---|---|
504 | Gateway Timeout | GATEWAY_TIMEOUT | RFC7231, Section 6.6.5 |
The server, while acting as a gateway or proxy, did not receive a timely response from the upstream server specified by the URI (e.g. HTTP, FTP, LDAP) or some other auxiliary server (e.g. DNS) it needed to access in attempting to complete the request.
Status code | Error name | Error type | Reference |
---|---|---|---|
505 | HTTP Version Not Supported | HTTP_VERSION_NOT_SUPPORTED | RFC7231, Section 6.6.6 |
The server does not support, or refuses to support, the HTTP protocol version that was used in the request message. The server is indicating that it is unable or unwilling to complete the request using the same major version as the client, as described in section 3.1, other than with this error message. The response SHOULD contain an entity describing why that version is not supported and what other protocols are supported by that server.
Status code | Error name | Error type | Reference |
---|---|---|---|
506 | Variant Also Negotiates | VARIANT_ALSO_NEGOTIATES | RFC2295 |
The 506 status code indicates that the server has an internal configuration error: the chosen variant resource is configured to engage in transparent content negotiation itself, and is therefore not a proper end point in the negotiation process.
Status code | Error name | Error type | Reference |
---|---|---|---|
507 | Insufficient Storage (WebDAV) | INSUFFICIENT_STORAGE | RFC4918 |
The 507 (Insufficient Storage) status code means the method could not be performed on the resource because the server is unable to store the representation needed to successfully complete the request. This condition is considered to be temporary. If the request that received this status code was the result of a user action, the request MUST NOT be repeated until it is requested by a separate user action.
Status code | Error name | Error type | Reference |
---|---|---|---|
508 | Loop Detected (WebDAV) | LOOP_DETECTED | RFC5842 |
The 508 (Loop Detected) status code indicates that the server terminated an operation because it encountered an infinite loop while processing a request with Depth: infinity. This status indicates that the entire operation failed.
Status code | Error name | Error type | Reference |
---|---|---|---|
509 | Bandwidth Limit Exceeded | BANDWIDTH_LIMIT_EXCEEDED | No reference |
This status code, while used by many servers, is not specified in any RFCs.
Status code | Error name | Error type | Reference |
---|---|---|---|
510 | Not Extended | NOT_EXTENDED | RFC2774 |
The policy for accessing the resource has not been met in the request. The server should send back all the information necessary for the client to issue an extended request. It is outside the scope of this specification to specify how the extensions inform the client.
Status code | Error name | Error type | Reference |
---|---|---|---|
511 | Network Authentication Required | NETWORK_AUTHENTICATION_REQUIRED | RFC6585 |
The 511 status code indicates that the client needs to authenticate to gain network access. The response representation SHOULD contain a link to a resource that allows the user to submit credentials.
Status code | Error name | Error type | Reference |
---|---|---|---|
598 | Network read timeout error | NETWORK_READ_TIMEOUT_ERROR | No reference |
This status code is not specified in any RFCs, but is used by some HTTP proxies to signal a network read timeout behind the proxy to a client in front of the proxy.
Status code | Error name | Error type | Reference |
---|---|---|---|
599 | Network read timeout error | NETWORK_CONNECT_TIMEOUT_ERROR | No reference |
This status code is not specified in any RFCs, but is used by some HTTP proxies to signal a network read timeout behind the proxy to a client in front of the proxy.
FAQs
List of common errors for RESTful API
The npm package error-types receives a total of 1 weekly downloads. As such, error-types popularity was classified as not popular.
We found that error-types demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.