-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
feat: Add response error codes #9500
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+1,443
−1,258
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4102,3 +4102,213 @@ describe('sendEmail', () => { | |
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe('custom HTTP codes', () => { | ||
| it('should set custom statusCode in save hook', async () => { | ||
| Parse.Cloud.beforeSave('TestObject', (req, res) => { | ||
| res.status(201); | ||
| }); | ||
|
|
||
| const request = await fetch('http://localhost:8378/1/classes/TestObject', { | ||
| method: 'POST', | ||
| headers: { | ||
| 'X-Parse-Application-Id': 'test', | ||
| 'X-Parse-REST-API-Key': 'rest', | ||
| } | ||
| }); | ||
|
|
||
| expect(request.status).toBe(201); | ||
| }); | ||
|
|
||
| it('should set custom headers in save hook', async () => { | ||
| Parse.Cloud.beforeSave('TestObject', (req, res) => { | ||
| res.setHeader('X-Custom-Header', 'custom-value'); | ||
| }); | ||
|
|
||
| const request = await fetch('http://localhost:8378/1/classes/TestObject', { | ||
| method: 'POST', | ||
| headers: { | ||
| 'X-Parse-Application-Id': 'test', | ||
| 'X-Parse-REST-API-Key': 'rest', | ||
| } | ||
| }); | ||
|
|
||
| expect(request.headers.get('X-Custom-Header')).toBe('custom-value'); | ||
| }); | ||
|
|
||
| it('should set custom statusCode in delete hook', async () => { | ||
| Parse.Cloud.beforeDelete('TestObject', (req, res) => { | ||
| res.status(201); | ||
| return true | ||
| }); | ||
|
|
||
| const obj = new Parse.Object('TestObject'); | ||
| await obj.save(); | ||
|
|
||
| const request = await fetch(`http://localhost:8378/1/classes/TestObject/${obj.id}`, { | ||
| method: 'DELETE', | ||
| headers: { | ||
| 'X-Parse-Application-Id': 'test', | ||
| 'X-Parse-REST-API-Key': 'rest', | ||
| } | ||
| }); | ||
|
|
||
| expect(request.status).toBe(201); | ||
| }); | ||
|
|
||
| it('should set custom headers in delete hook', async () => { | ||
| Parse.Cloud.beforeDelete('TestObject', (req, res) => { | ||
| res.setHeader('X-Custom-Header', 'custom-value'); | ||
| }); | ||
|
|
||
| const obj = new TestObject(); | ||
| await obj.save(); | ||
| const request = await fetch(`http://localhost:8378/1/classes/TestObject/${obj.id}`, { | ||
| method: 'DELETE', | ||
| headers: { | ||
| 'X-Parse-Application-Id': 'test', | ||
| 'X-Parse-REST-API-Key': 'rest', | ||
| } | ||
| }); | ||
|
|
||
| expect(request.headers.get('X-Custom-Header')).toBe('custom-value'); | ||
| }); | ||
|
|
||
| it('should set custom statusCode in find hook', async () => { | ||
| Parse.Cloud.beforeFind('TestObject', (req, res) => { | ||
| res.status(201); | ||
| }); | ||
|
|
||
| const request = await fetch('http://localhost:8378/1/classes/TestObject', { | ||
| headers: { | ||
| 'X-Parse-Application-Id': 'test', | ||
| 'X-Parse-REST-API-Key': 'rest', | ||
| } | ||
| }); | ||
|
|
||
| expect(request.status).toBe(201); | ||
| }); | ||
|
|
||
| it('should set custom headers in find hook', async () => { | ||
| Parse.Cloud.beforeFind('TestObject', (req, res) => { | ||
| res.setHeader('X-Custom-Header', 'custom-value'); | ||
| }); | ||
|
|
||
| const request = await fetch('http://localhost:8378/1/classes/TestObject', { | ||
| headers: { | ||
| 'X-Parse-Application-Id': 'test', | ||
| 'X-Parse-REST-API-Key': 'rest', | ||
| } | ||
| }); | ||
|
|
||
| expect(request.headers.get('X-Custom-Header')).toBe('custom-value'); | ||
| }); | ||
|
|
||
| it('should set custom statusCode in cloud function', async () => { | ||
| Parse.Cloud.define('customStatusCode', (req, res) => { | ||
| res.status(201); | ||
| return true; | ||
| }); | ||
|
|
||
| const response = await fetch('http://localhost:8378/1/functions/customStatusCode', { | ||
| method: 'POST', | ||
| headers: { | ||
| 'X-Parse-Application-Id': 'test', | ||
| 'X-Parse-REST-API-Key': 'rest', | ||
| } | ||
| }); | ||
|
|
||
| expect(response.status).toBe(201); | ||
| }); | ||
|
|
||
| it('should set custom headers in cloud function', async () => { | ||
| Parse.Cloud.define('customHeaders', (req, res) => { | ||
| res.setHeader('X-Custom-Header', 'custom-value'); | ||
| return true; | ||
| }); | ||
|
|
||
| const response = await fetch('http://localhost:8378/1/functions/customHeaders', { | ||
| method: 'POST', | ||
| headers: { | ||
| 'X-Parse-Application-Id': 'test', | ||
| 'X-Parse-REST-API-Key': 'rest', | ||
| } | ||
| }); | ||
|
|
||
| expect(response.headers.get('X-Custom-Header')).toBe('custom-value'); | ||
| }); | ||
|
|
||
| it('should set custom statusCode in beforeLogin hook', async () => { | ||
| Parse.Cloud.beforeLogin((req, res) => { | ||
| res.status(201); | ||
| }); | ||
|
|
||
| await Parse.User.signUp('[email protected]', 'password'); | ||
| const response = await fetch('http://localhost:8378/1/login', { | ||
| method: 'POST', | ||
| headers: { | ||
| 'X-Parse-Application-Id': 'test', | ||
| 'X-Parse-REST-API-Key': 'rest', | ||
| }, | ||
| body: JSON.stringify({ username: '[email protected]', password: 'password' }) | ||
| }); | ||
|
|
||
| expect(response.status).toBe(201); | ||
| }); | ||
|
|
||
| it('should set custom headers in beforeLogin hook', async () => { | ||
| Parse.Cloud.beforeLogin((req, res) => { | ||
| res.setHeader('X-Custom-Header', 'custom-value'); | ||
| }); | ||
|
|
||
| await Parse.User.signUp('[email protected]', 'password'); | ||
| const response = await fetch('http://localhost:8378/1/login', { | ||
| method: 'POST', | ||
| headers: { | ||
| 'X-Parse-Application-Id': 'test', | ||
| 'X-Parse-REST-API-Key': 'rest', | ||
| }, | ||
| body: JSON.stringify({ username: '[email protected]', password: 'password' }) | ||
| }); | ||
|
|
||
| expect(response.headers.get('X-Custom-Header')).toBe('custom-value'); | ||
| }); | ||
|
|
||
| it('should set custom statusCode in file trigger', async () => { | ||
| Parse.Cloud.beforeSave(Parse.File, (req, res) => { | ||
| res.status(201); | ||
| }); | ||
|
|
||
| const file = new Parse.File('test.txt', [1, 2, 3]); | ||
| const response = await fetch('http://localhost:8378/1/files/test.txt', { | ||
| method: 'POST', | ||
| headers: { | ||
| 'X-Parse-Application-Id': 'test', | ||
| 'X-Parse-REST-API-Key': 'rest', | ||
| 'Content-Type': 'text/plain', | ||
| }, | ||
| body: file.getData() | ||
| }); | ||
|
|
||
| expect(response.status).toBe(201); | ||
| }); | ||
|
|
||
| it('should set custom headers in file trigger', async () => { | ||
| Parse.Cloud.beforeSave(Parse.File, (req, res) => { | ||
| res.setHeader('X-Custom-Header', 'custom-value'); | ||
| }); | ||
|
|
||
| const file = new Parse.File('test.txt', [1, 2, 3]); | ||
| const response = await fetch('http://localhost:8378/1/files/test.txt', { | ||
| method: 'POST', | ||
| headers: { | ||
| 'X-Parse-Application-Id': 'test', | ||
| 'X-Parse-REST-API-Key': 'rest', | ||
| 'Content-Type': 'text/plain', | ||
| }, | ||
| body: file.getData() | ||
| }); | ||
|
|
||
| expect(response.headers.get('X-Custom-Header')).toBe('custom-value'); | ||
| }); | ||
|
Comment on lines
+4296
to
+4313
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same issue: This test has the same problem as the previous one. it('should set custom headers in file trigger', async () => {
Parse.Cloud.beforeSave(Parse.File, (req, res) => {
res.setHeader('X-Custom-Header', 'custom-value');
});
const file = new Parse.File('test.txt', [1, 2, 3]);
const response = await fetch('http://localhost:8378/1/files/test.txt', {
method: 'POST',
headers: {
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest',
'Content-Type': 'text/plain',
},
- body: file.getData()
+ body: new Uint8Array([1, 2, 3])
});
expect(response.headers.get('X-Custom-Header')).toBe('custom-value');
});🤖 Prompt for AI Agents |
||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug:
file.getData()returns a Promise and must be awaited.Parse.File.getData()returns a Promise, but it's passed directly to the fetchbodywithout awaiting. This will cause the request body to be[object Promise]instead of the actual file data.it('should set custom statusCode in file trigger', async () => { Parse.Cloud.beforeSave(Parse.File, (req, res) => { res.status(201); }); const file = new Parse.File('test.txt', [1, 2, 3]); const response = await fetch('http://localhost:8378/1/files/test.txt', { method: 'POST', headers: { 'X-Parse-Application-Id': 'test', 'X-Parse-REST-API-Key': 'rest', 'Content-Type': 'text/plain', }, - body: file.getData() + body: new Uint8Array([1, 2, 3]) }); expect(response.status).toBe(201); });Alternatively, since the file hasn't been saved yet, you can use the raw data directly or create a proper buffer/blob for the request body.
🤖 Prompt for AI Agents