Skip to content

Commit 88d90ec

Browse files
authored
Add RequestError typescript definition (#248)
Errors triggered by nano are extended with additional fields, this commits adds the typescript definition for them. The name "RequestError" was chosen because it seems like it all nano errors are triggered by a request (a 'socket' or a 'couch' error). I considered "NanoError", but the full type `nano.NanoError` doesn't sound better than `nano.RequestError` and no other interface have been prefixed with "Nano".
1 parent 64ba7c4 commit 88d90ec

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

lib/nano.d.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,31 @@ declare namespace nano {
3636
request?(params: any): void;
3737
}
3838

39-
type Callback<R> = (error: any, response: R, headers?: any) => void;
39+
type Callback<R> = (error: RequestError | null, response: R, headers?: any) => void;
40+
41+
// An error triggered by nano
42+
interface RequestError extends Error {
43+
// An error code.
44+
error?: string; // 'not_found', 'file_exists'
45+
// Human readable reason for the error.
46+
reason?: string; // 'missing', 'The database could not be created, the file already exists.';
47+
// Was the problem at the socket or couch level
48+
scope?: 'couch' | 'socket';
49+
// Status code returned by the server
50+
statusCode?: number; // 404;
51+
// Request sent to Couch
52+
request?: {
53+
method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
54+
headers?: { [key: string]: string | number };
55+
uri?: string; // 'http://couchhost:5984/db/tsp2',
56+
qs?: any; // { revs_info: true }
57+
};
58+
// Response headers
59+
headers?: { [key: string]: string | number };
60+
// Error identifier
61+
errid?: 'non_200' | 'request'; // string; // 'non_200'
62+
description?: string;
63+
}
4064

4165
interface ServerScope {
4266
readonly config: ServerConfig;

0 commit comments

Comments
 (0)