Skip to content

Missing action Function Returns 500 Instead of 405 #5507

@joshboley

Description

@joshboley

What version of Remix are you using?

1.13.0

Are all your remix dependencies & dev-dependencies using the same version?

  • Yes

Steps to Reproduce

  • Make any Remix route (page, resource, or api route) with an exported loader, but no action
  • Make a GET request to the route, notice success
  • Make a POST (or PUT, etc) request to the route, notice a 500 response

Example Route:

// routes/api/health.tsx
import {json} from '@remix-run/node'

export async function loader() {
  return json({
    status: 'success',
  })
}

Expected Behavior

During the non-GET request, POST in this example, a 405 status code should be returned, based on this discussion.

Actual Behavior

The returned status code is 500. Note however, that the Remix server outputs 405, but that is not the status code actually received by the caller.

Example curl:

curl -X POST http://localhost:3000/api/health -v

*   Trying 127.0.0.1:3000...
* Connected to localhost (127.0.0.1) port 3000 (#0)
> POST /api/health HTTP/1.1
> Host: localhost:3000
> User-Agent: curl/7.79.1
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 500 Internal Server Error
< content-type: text/plain; charset=utf-8
< Vary: Accept-Encoding
< Date: Fri, 17 Feb 2023 22:03:04 GMT
< Connection: keep-alive
< Keep-Alive: timeout=5
< Transfer-Encoding: chunked
<
Unexpected Server Error

* Connection #0 to host localhost left intact
[object Object]%

But note the output in the terminal from the running Remix server:

POST /api/health 500 - - 159.584 ms
ErrorResponse {
  status: 405,
  statusText: 'Method Not Allowed',
  internal: true,
  data: 'Error: You made a POST request to "/logout" but did not provide an `action` for route "routes/__app/logout", so there is no way to handle the request.',
  error: Error: You made a POST request to "/logout" but did not provide an `action` for route "routes/__app/logout", so there is no way to handle the request.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions