mirror of
https://github.com/n8n-io/n8n-nodes-starter.git
synced 2025-10-28 14:12:24 -05:00
Handle errors from example node and clarified options about credentials and properties
This commit is contained in:
parent
e2b4595066
commit
abe033d7a1
3 changed files with 38 additions and 30 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import {
|
||||
IAuthenticateGeneric,
|
||||
ICredentialDataDecryptedObject,
|
||||
ICredentialTestRequest,
|
||||
ICredentialType,
|
||||
|
|
@ -17,12 +18,6 @@ export class HttpBinApi implements ICredentialType {
|
|||
type: 'string',
|
||||
default: '',
|
||||
},
|
||||
// {
|
||||
// displayName: "API Key",
|
||||
// name: "apiKey",
|
||||
// type: "string",
|
||||
// default: "",
|
||||
// },
|
||||
{
|
||||
displayName: 'Domain',
|
||||
name: 'domain',
|
||||
|
|
@ -31,26 +26,21 @@ export class HttpBinApi implements ICredentialType {
|
|||
},
|
||||
];
|
||||
|
||||
// authenticate = {
|
||||
// type: "headerAuth",
|
||||
// properties: {
|
||||
// name: "api-key",
|
||||
// value: "={{$credentials.apiKey}}",
|
||||
// },
|
||||
// } as IAuthenticateHeaderAuth;
|
||||
|
||||
authenticate = async (
|
||||
credentials: ICredentialDataDecryptedObject,
|
||||
requestOptions: IHttpRequestOptions,
|
||||
): Promise<IHttpRequestOptions> => {
|
||||
const headers = requestOptions.headers || {};
|
||||
const authentication = { Authorization: `Bearer ${credentials.token}` };
|
||||
Object.assign(requestOptions, {
|
||||
headers: { ...authentication, ...headers },
|
||||
});
|
||||
return requestOptions;
|
||||
};
|
||||
// This allows the credential to be used by other parts of n8n
|
||||
// stating how this credential is injected as part of the request
|
||||
// An example is the Http Request node that can make generic calls
|
||||
// reusing this credential
|
||||
authenticate = {
|
||||
type: 'generic',
|
||||
properties: {
|
||||
header: {
|
||||
name: 'api-key',
|
||||
value: '={{$credentials.apiKey}}',
|
||||
},
|
||||
},
|
||||
} as IAuthenticateGeneric;
|
||||
|
||||
// The block below tells how this credential can be tested
|
||||
test: ICredentialTestRequest = {
|
||||
request: {
|
||||
baseURL: '={{$credentials?.domain}}',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue