0.3.2 • Published 6 years ago

kinvey-datalink-errors v0.3.2

Weekly downloads
116
License
Apache-2.0
Repository
github
Last release
6 years ago

Build Status

Kinvey Datalink Errors

Create Kinvey-formatted errors for Datalinks

Installation

npm install kinvey-datalink-errors

Usage

Kinvey Errors exposes a single function, generateKinveyError which takes the error type and an error. The error can either be a string or a JavaScript Error.

var kinveyErrors = require('kinvey-datalink-errors');

var myError = kinveyErrors.generateKinveyError("NotFound", "The record is not found"); // a string
var myError = kinveyErrors.generateKinveyError("NotFound, new Error("The record is not found")); // an error

The library returns the error passed as a Kinvey-formatted error.

{
  error: "NotFound",
  description: "The requested entity or entites were not found in the collection."
  debug: "THe record is not found"
  statusCode: 404
}

If an error object is passed and it contains a stack trace, the stack trace will also be included in the error object.

Error Types

This library exposes the following error types:

Error TypeDescription
NotFoundUsed when an entity is not found. Note: This should only be used on getById and deleteById commands. Otherwise, an empty array should be returned (for getAll, getByQuery) or a count of 0 (for deleteByQuery, countByQuery).
BadRequestUsed for any invalid input - queries, body, etc.
UnauthorizedUsed when the operation or user is unauthorized to perform the operation.
ForbiddenUsed when an operation is forbidden.
NotAllowedUsed when the request is not allowed
NotImplementedUsed when a specific method is not implemented
RuntimeErrorUsed for any type of runtime error